下面列出了怎么用net.minecraft.util.Rotation的API类实例代码及写法,或者点击链接到github查看源代码。
private void create(World p_191092_1_, ChunkProviderTofu p_191092_2_, Random p_191092_3_, int p_191092_4_, int p_191092_5_) {
Rotation rotation = Rotation.NONE;
ChunkPrimer chunkprimer = new ChunkPrimer();
p_191092_2_.setBlocksInChunk(p_191092_4_, p_191092_5_, chunkprimer);
int i = 5;
int j = 5;
int k = chunkprimer.findGroundBlockIdx(7, 7);
int l = chunkprimer.findGroundBlockIdx(7, 7 + j);
int i1 = chunkprimer.findGroundBlockIdx(7 + i, 7);
int j1 = chunkprimer.findGroundBlockIdx(7 + i, 7 + j);
int k1 = Math.min(Math.min(k, l), Math.min(i1, j1));
BlockPos blockpos = new BlockPos(p_191092_4_ * 16 + 8, k1, p_191092_5_ * 16 + 8);
List<TofuCastlePiece.TofuCastleTemplate> list = Lists.<TofuCastlePiece.TofuCastleTemplate>newLinkedList();
TofuCastlePiece.generateCore(p_191092_1_.getSaveHandler().getStructureTemplateManager(), blockpos, rotation, list, p_191092_3_);
this.components.addAll(list);
this.updateBoundingBox();
this.isValid = true;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot){
case COUNTERCLOCKWISE_90:
case CLOCKWISE_90:
switch (state.getValue(LOG_AXIS)){
case X:
return state.withProperty(LOG_AXIS, EnumAxis.Z);
case Z:
return state.withProperty(LOG_AXIS, EnumAxis.X);
default:
return state;
}
default:
return state;
}
}
@Override
public void rotate(Rotation rotationIn)
{
List<EnumFacing> newList = new ArrayList<EnumFacing>();
for (EnumFacing side : this.enabledSides)
{
newList.add(rotationIn.rotate(side));
}
this.enabledSides.clear();
this.enabledSides.addAll(newList);
this.updateValidSides(false);
super.rotate(rotationIn);
}
/**
* Returns the rotation that would transform <b>facingOriginal</b> into <b>facingRotated</b>.
* @param facingOriginal
* @param facingRotated
* @return
*/
public static Rotation getRotation(EnumFacing facingOriginal, EnumFacing facingRotated)
{
if (facingOriginal.getAxis() == EnumFacing.Axis.Y ||
facingRotated.getAxis() == EnumFacing.Axis.Y || facingOriginal == facingRotated)
{
return Rotation.NONE;
}
if (facingRotated == facingOriginal.getOpposite())
{
return Rotation.CLOCKWISE_180;
}
return facingRotated == facingOriginal.rotateY() ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
}
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
if (ConfigHolder.abandonedBaseRarity == 0 ||
world.getWorldType() == WorldType.FLAT ||
world.provider.getDimensionType() != DimensionType.OVERWORLD ||
!world.getWorldInfo().isMapFeaturesEnabled()) {
return; //do not generate in flat worlds, or in non-surface worlds
}
BlockPos randomPos = new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8);
if (random.nextInt(ConfigHolder.abandonedBaseRarity) == 0) {
int variantNumber = random.nextInt(3);
Rotation rotation = Rotation.values()[random.nextInt(Rotation.values().length)];
ResourceLocation templateId = new ResourceLocation(GTValues.MODID, "abandoned_base/abandoned_base_1_" + variantNumber);
Template template = TemplateManager.getBuiltinTemplate(world, templateId);
BlockPos originPos = template.getZeroPositionWithTransform(randomPos, Mirror.NONE, rotation);
originPos = TemplateManager.calculateAverageGroundLevel(world, originPos, template.getSize());
template.addBlocksToWorld(world, originPos, new PlacementSettings().setRotation(rotation));
}
}
public void setSubRegionRotation(SchematicPlacement placement, String regionName, Rotation rotation, IMessageConsumer feedback)
{
if (placement.isLocked())
{
feedback.addMessage(MessageType.ERROR, "litematica.message.placement.cant_modify_is_locked");
return;
}
SubRegionPlacement subPlacement = placement.getRelativeSubRegionPlacement(regionName);
if (subPlacement != null)
{
this.onPrePlacementChange(placement);
placement.setSubRegionRotation(regionName, rotation);
this.onPlacementRegionModified(placement);
}
}
@Override
public void rotate(Rotation rotationIn)
{
List<EnumFacing> newList = new ArrayList<EnumFacing>();
for (EnumFacing side : this.labels)
{
newList.add(rotationIn.rotate(side));
}
this.labels.clear();
this.labels.addAll(newList);
this.labelMask = this.getLabelMask(false);
super.rotate(rotationIn);
}
private static void generateUnderGround(TemplateManager templateManager, BlockPos pos, Rotation rotation, List<TofuCastleTemplate> list, Random random) {
BlockPos pos1 = new BlockPos(pos.down(19));
BlockPos pos2 = new BlockPos(pos1.south(23).east(4));
BlockPos pos3 = new BlockPos(pos1.south(-15).east(4));
BlockPos pos4 = new BlockPos(pos1.south(23 + 15).down(11));
generateUnderSub(templateManager, pos2, rotation, list, random);
generateUnderSub(templateManager, pos3, rotation, list, random);
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_undermain"));
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos4, rotation, "tofucastle_bossroom"));
}
private static void generateUnderSub(TemplateManager templateManager, BlockPos pos, Rotation rotation, List<TofuCastleTemplate> list, Random random) {
//east
BlockPos pos1 = new BlockPos(pos.south(4).east(15));
//west
BlockPos pos2 = new BlockPos(pos.south(4).east(-7));
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos, rotation, "tofucastle_normalroom"));
//east
if (random.nextInt(1) == 0) {
if (random.nextInt(1) == 0) {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_foodcontainer"));
} else {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_foodcontainer2"));
}
} else {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_eastroom"));
}
//west
if (random.nextInt(2) == 0) {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos2, rotation, "tofucastle_westroom"));
} else {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos2, rotation, "tofucastle_westbedroom"));
}
}
private static void generatesub(TemplateManager templateManager, BlockPos pos, Rotation rotation, List<TofuCastleTemplate> list, Random random) {
//generate entrance
BlockPos pos1 = new BlockPos(pos.south(23).east(4));
BlockPos pos2 = new BlockPos(pos.south(-15).east(4));
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_entrance"));
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos2, rotation, "tofucastle_entrance"));
}
public static Rotation getReverseRotation(Rotation rotation)
{
switch (rotation)
{
case CLOCKWISE_90: return Rotation.COUNTERCLOCKWISE_90;
case COUNTERCLOCKWISE_90: return Rotation.CLOCKWISE_90;
case CLOCKWISE_180: return Rotation.CLOCKWISE_180;
default: return Rotation.NONE;
}
}
private TofuCastleTemplate(TemplateManager manager, BlockPos pos, Rotation rotation, Mirror mirror, String templateName) {
super(0);
this.templatePosition = pos;
this.rotation = rotation;
this.mirror = mirror;
this.templateName = templateName;
this.loadTemplate(manager);
}
@Override
protected void readStructureFromNBT(NBTTagCompound compound, TemplateManager manager) {
super.readStructureFromNBT(compound, manager);
this.isAleadyBossRoomGen = compound.getBoolean("BossRoom");
this.templateName = compound.getString("Template");
this.rotation = Rotation.valueOf(compound.getString("Rot"));
this.mirror = Mirror.valueOf(compound.getString("Mi"));
this.loadTemplate(manager);
}
public static Vec3d transformedVec3d(Vec3d vec, Mirror mirrorIn, Rotation rotationIn)
{
double x = vec.x;
double y = vec.y;
double z = vec.z;
boolean isMirrored = true;
switch (mirrorIn)
{
case LEFT_RIGHT:
z = 1.0D - z;
break;
case FRONT_BACK:
x = 1.0D - x;
break;
default:
isMirrored = false;
}
switch (rotationIn)
{
case COUNTERCLOCKWISE_90:
return new Vec3d(z, y, 1.0D - x);
case CLOCKWISE_90:
return new Vec3d(1.0D - z, y, x);
case CLOCKWISE_180:
return new Vec3d(1.0D - x, y, 1.0D - z);
default:
return isMirrored ? new Vec3d(x, y, z) : vec;
}
}
/**
* Mirrors and then rotates the given position around the origin
*/
public static BlockPos getTransformedBlockPos(BlockPos pos, Mirror mirror, Rotation rotation)
{
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
boolean isMirrored = true;
switch (mirror)
{
// LEFT_RIGHT is essentially NORTH_SOUTH
case LEFT_RIGHT:
z = -z;
break;
// FRONT_BACK is essentially EAST_WEST
case FRONT_BACK:
x = -x;
break;
default:
isMirrored = false;
}
switch (rotation)
{
case CLOCKWISE_90:
return new BlockPos(-z, y, x);
case COUNTERCLOCKWISE_90:
return new BlockPos( z, y, -x);
case CLOCKWISE_180:
return new BlockPos(-x, y, -z);
default:
return isMirrored ? new BlockPos(x, y, z) : pos;
}
}
public static Vec3d getTransformedPosition(Vec3d originalPos, Mirror mirror, Rotation rotation)
{
double x = originalPos.x;
double y = originalPos.y;
double z = originalPos.z;
boolean transformed = true;
switch (mirror)
{
case LEFT_RIGHT:
z = 1.0D - z;
break;
case FRONT_BACK:
x = 1.0D - x;
break;
default:
transformed = false;
}
switch (rotation)
{
case COUNTERCLOCKWISE_90:
return new Vec3d(z, y, 1.0D - x);
case CLOCKWISE_90:
return new Vec3d(1.0D - z, y, x);
case CLOCKWISE_180:
return new Vec3d(1.0D - x, y, 1.0D - z);
default:
return transformed ? new Vec3d(x, y, z) : originalPos;
}
}
public static Rotation getReverseRotation(Rotation rotationIn)
{
switch (rotationIn)
{
case COUNTERCLOCKWISE_90:
return Rotation.CLOCKWISE_90;
case CLOCKWISE_90:
return Rotation.COUNTERCLOCKWISE_90;
case CLOCKWISE_180:
return Rotation.CLOCKWISE_180;
default:
return rotationIn;
}
}
public static String getRotationNameShort(Rotation rotation)
{
switch (rotation)
{
case CLOCKWISE_90: return "CW_90";
case CLOCKWISE_180: return "CW_180";
case COUNTERCLOCKWISE_90: return "CCW_90";
case NONE:
default: return "NONE";
}
}
/**
* Mirrors and then rotates the given position around the origin
*/
public static BlockPosEU getTransformedBlockPos(BlockPosEU pos, Mirror mirror, Rotation rotation)
{
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
boolean isMirrored = true;
switch (mirror)
{
// LEFT_RIGHT is essentially NORTH_SOUTH
case LEFT_RIGHT:
z = -z;
break;
// FRONT_BACK is essentially EAST_WEST
case FRONT_BACK:
x = -x;
break;
default:
isMirrored = false;
}
switch (rotation)
{
case CLOCKWISE_90:
return new BlockPosEU(-z, y, x, pos.getDimension(), pos.getFacing());
case COUNTERCLOCKWISE_90:
return new BlockPosEU( z, y, -x, pos.getDimension(), pos.getFacing());
case CLOCKWISE_180:
return new BlockPosEU(-x, y, -z, pos.getDimension(), pos.getFacing());
default:
return isMirrored ? new BlockPosEU(x, y, z, pos.getDimension(), pos.getFacing()) : pos;
}
}
@Inject(method = "withRotation", at = @At("HEAD"), cancellable = true)
private void fixRailRotation(IBlockState state, Rotation rot, CallbackInfoReturnable<IBlockState> cir)
{
if (Configs.Generic.FIX_RAIL_ROTATION.getBooleanValue() && rot == Rotation.CLOCKWISE_180)
{
BlockRailBase.EnumRailDirection dir = null;
if (((Object) this) instanceof BlockRail)
{
dir = state.getValue(BlockRail.SHAPE);
}
else if (((Object) this) instanceof BlockRailDetector)
{
dir = state.getValue(BlockRailDetector.SHAPE);
}
else if (((Object) this) instanceof BlockRailPowered)
{
dir = state.getValue(BlockRailPowered.SHAPE);
}
// Fix the incomplete switch statement causing the ccw_90 rotation being used instead
// for the 180 degree rotation of the straight rails.
if (dir == BlockRailBase.EnumRailDirection.EAST_WEST || dir == BlockRailBase.EnumRailDirection.NORTH_SOUTH)
{
cir.setReturnValue(state);
cir.cancel();
}
}
}
public void setRotation(SchematicPlacement placement, Rotation rotation, IMessageConsumer feedback)
{
if (placement.isLocked())
{
feedback.addMessage(MessageType.ERROR, "litematica.message.placement.cant_modify_is_locked");
return;
}
if (placement.getRotation() != rotation)
{
this.onPrePlacementChange(placement);
placement.setRotation(rotation);
this.onPlacementModified(placement);
}
}
void resetToOriginalValues()
{
this.pos = this.defaultPos;
this.rotation = Rotation.NONE;
this.mirror = Mirror.NONE;
this.enabled = true;
this.ignoreEntities = false;
}
public boolean isRegionPlacementModified(BlockPos originalPosition)
{
return this.isEnabled() == false ||
this.ignoreEntities() ||
this.getMirror() != Mirror.NONE ||
this.getRotation() != Rotation.NONE ||
this.getPos().equals(originalPosition) == false;
}
void setSubRegionRotation(String regionName, Rotation rotation)
{
SubRegionPlacement subRegion = this.relativeSubRegionPlacements.get(regionName);
if (subRegion != null)
{
subRegion.setRotation(rotation);
}
}
public static IBlockState getUntransformedBlockState(IBlockState state, SchematicPlacement schematicPlacement, String subRegionName)
{
SubRegionPlacement placement = schematicPlacement.getRelativeSubRegionPlacement(subRegionName);
if (placement != null)
{
final Rotation rotationCombined = PositionUtils.getReverseRotation(schematicPlacement.getRotation().add(placement.getRotation()));
final Mirror mirrorMain = schematicPlacement.getMirror();
Mirror mirrorSub = placement.getMirror();
if (mirrorSub != Mirror.NONE &&
(schematicPlacement.getRotation() == Rotation.CLOCKWISE_90 ||
schematicPlacement.getRotation() == Rotation.COUNTERCLOCKWISE_90))
{
mirrorSub = mirrorSub == Mirror.FRONT_BACK ? Mirror.LEFT_RIGHT : Mirror.FRONT_BACK;
}
if (rotationCombined != Rotation.NONE)
{
state = state.withRotation(rotationCombined);
}
if (mirrorSub != Mirror.NONE)
{
state = state.withMirror(mirrorSub);
}
if (mirrorMain != Mirror.NONE)
{
state = state.withMirror(mirrorMain);
}
}
return state;
}
public TaskMoveArea(int dimension, BlockPos posSrcStart, BlockPos posSrcEnd, BlockPos posDstStart,
Rotation rotationDst, Mirror mirrorDst, UUID wandUUID, int blocksPerTick)
{
this.posSrcStart = posSrcStart;
this.posDstStart = posDstStart;
this.rotation = rotationDst;
this.mirror = mirrorDst;
this.wandUUID = wandUUID;
this.dimension = dimension;
this.blocksPerTick = blocksPerTick;
this.boxRelative = new BlockPosBox(BlockPos.ORIGIN, posSrcEnd.subtract(posSrcStart));
this.boxSource = new BlockPosBox(posSrcStart, posSrcEnd);
this.handledPositions = new HashSet<BlockPos>();
}
@Override
public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileFrequencyOwner) {
((TileFrequencyOwner) tile).rotate();
}
return state;
}
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
{
TileEntityEnderUtilities te = getTileEntitySafely(world, pos, TileEntityEnderUtilities.class);
if (te != null)
{
te.rotate(Rotation.CLOCKWISE_90);
IBlockState state = world.getBlockState(pos).getActualState(world, pos);
world.notifyBlockUpdate(pos, state, state, 3);
return true;
}
return false;
}
private void moveAreaImmediate(ItemStack stack, World world, EntityPlayer player, BlockPos posSrc1, BlockPos posSrc2, BlockPos posDst1,
Mirror mirror, Rotation rotation)
{
PlacementSettings placement = new PlacementSettings();
placement.setMirror(mirror);
placement.setRotation(rotation);
placement.setIgnoreEntities(false);
placement.setReplacedBlock(Blocks.BARRIER); // meh
ReplaceMode replace = WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.MOVE_DST) ? ReplaceMode.EVERYTHING : ReplaceMode.NOTHING;
TemplateEnderUtilities template = new TemplateEnderUtilities(placement, replace);
template.takeBlocksFromWorld(world, posSrc1, posSrc2.subtract(posSrc1), true, false);
this.deleteArea(stack, world, player, posSrc1, posSrc2, true);
template.addBlocksToWorld(world, posDst1);
}
public static void generateCore(TemplateManager templateManager, BlockPos pos, Rotation rotation, List<TofuCastleTemplate> list, Random random) {
list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos, rotation, "tofucastle_main"));
generatesub(templateManager, pos, rotation, list, random);
generateUnderGround(templateManager, pos, rotation, list, random);
}