下面列出了怎么用net.minecraft.util.Mirror的API类实例代码及写法,或者点击链接到github查看源代码。
@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 static float getMirroredYaw(float yaw, Mirror mirror)
{
yaw = MathHelper.wrapDegrees(yaw);
switch (mirror)
{
case LEFT_RIGHT:
yaw = 180.0F - yaw;
break;
case FRONT_BACK:
yaw = -yaw;
break;
default:
}
return yaw;
}
public void setSubRegionMirror(SchematicPlacement placement, String regionName, Mirror mirror, 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.setSubRegionMirror(regionName, mirror);
this.onPlacementRegionModified(placement);
}
}
public static void rotateEntity(Entity entity, double x, double y, double z, Rotation rotationCombined, Mirror mirrorMain, Mirror mirrorSub)
{
float rotationYaw = entity.rotationYaw;
if (mirrorMain != Mirror.NONE) { rotationYaw = entity.getMirroredYaw(mirrorMain); }
if (mirrorSub != Mirror.NONE) { rotationYaw = entity.getMirroredYaw(mirrorSub); }
if (rotationCombined != Rotation.NONE) { rotationYaw += entity.rotationYaw - entity.getRotatedYaw(rotationCombined); }
entity.setLocationAndAngles(x, y, z, rotationYaw, entity.rotationPitch);
entity.prevRotationYaw = rotationYaw;
entity.prevRotationPitch = entity.rotationPitch;
if (entity instanceof EntityLivingBase)
{
EntityLivingBase livingBase = (EntityLivingBase) entity;
livingBase.rotationYawHead = rotationYaw;
livingBase.prevRotationYawHead = rotationYaw;
livingBase.renderYawOffset = rotationYaw;
livingBase.prevRenderYawOffset = rotationYaw;
}
}
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 void placeBlockAtIndex(World world, int index, BlockPos posStart)
{
if (index < this.blocks.size())
{
TemplateEnderUtilities.TemplateBlockInfo blockInfo = this.blocks.get(index);
BlockPos pos = transformedBlockPos(this.placement, blockInfo.pos).add(posStart);
IBlockState stateNew = blockInfo.blockState;
if (this.replaceMode == ReplaceMode.EVERYTHING ||
(this.replaceMode == ReplaceMode.WITH_NON_AIR && stateNew.getMaterial() != Material.AIR) || world.isAirBlock(pos))
{
Mirror mirror = this.placement.getMirror();
Rotation rotation = this.placement.getRotation();
stateNew = stateNew.withMirror(mirror).withRotation(rotation);
boolean success = false;
if (this.dropOldBlocks)
{
world.destroyBlock(pos, true);
}
/*
else
{
// Replace the block temporarily so that the old TE gets cleared for sure
BlockUtils.setBlockToAirWithoutSpillingContents(world, pos, 4);
}
*/
// Place the new block
success = world.setBlockState(pos, stateNew, 2);
if (success && blockInfo.tileEntityData != null)
{
TileUtils.createAndAddTileEntity(world, pos, blockInfo.tileEntityData, rotation, mirror);
}
}
}
}
/**
* 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 String getMirrorName(Mirror mirror)
{
switch (mirror)
{
case FRONT_BACK: return "FRONT_BACK";
case LEFT_RIGHT: return "LEFT_RIGHT";
case NONE:
default: return "NONE";
}
}
public void setMirror(SchematicPlacement placement, Mirror mirror, IMessageConsumer feedback)
{
if (placement.isLocked())
{
feedback.addMessage(MessageType.ERROR, "litematica.message.placement.cant_modify_is_locked");
return;
}
if (placement.getMirror() != mirror)
{
this.onPrePlacementChange(placement);
placement.setMirror(mirror);
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 setSubRegionMirror(String regionName, Mirror mirror)
{
SubRegionPlacement subRegion = this.relativeSubRegionPlacements.get(regionName);
if (subRegion != null)
{
subRegion.setMirror(mirror);
}
}
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 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;
}
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
switch (mirrorIn)
{
case LEFT_RIGHT:
return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
case FRONT_BACK:
return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
default:
return super.withMirror(state, mirrorIn);
}
}
private void setMirror(ItemStack stack, Mode mode, Mirror mirror)
{
int sel = this.getSelectionIndex(stack);
NBTTagCompound tag = this.getModeTag(stack, mode);
tag.setByte("Mirror_" + sel, (byte)mirror.ordinal());
tag.setBoolean("IsMirrored_" + sel, mirror != Mirror.NONE);
}
public Mirror getMirror(ItemStack stack, Mode mode)
{
int sel = this.getSelectionIndex(stack);
NBTTagCompound tag = this.getModeTag(stack, mode);
if (tag.getBoolean("IsMirrored_" + sel) && tag.hasKey("Mirror_" + sel, Constants.NBT.TAG_BYTE))
{
return Mirror.values()[tag.getByte("Mirror_" + sel) % Mirror.values().length];
}
return Mirror.NONE;
}
private void moveEndPosition(ItemStack stack, EntityPlayer player, boolean reverse)
{
EnumFacing direction = EntityUtils.getClosestLookingDirection(player);
Mode mode = Mode.getMode(stack);
BlockPosEU posStart = mode == Mode.CUBE || mode == Mode.WALLS ?
this.getPosition(stack, mode, POS_START) : this.getPerTemplateAreaCorner(stack, mode, POS_START);
BlockPosEU posEnd = this.getPosition(stack, mode, POS_END);
if (posEnd == null)
{
posEnd = posStart;
}
if (posStart != null && posEnd != null)
{
int v = reverse ? 1 : -1;
posEnd = posEnd.add(direction.getXOffset() * v, direction.getYOffset() * v, direction.getZOffset() * v);
if (mode == Mode.WALLS || mode == Mode.CUBE)
{
this.setPosition(posEnd, false, stack, player);
}
else
{
this.setPerTemplateAreaCorner(posEnd, mode, false, stack, player);
this.setAreaFacing(stack, mode, PositionUtils.getFacingFromPositions(posStart, posEnd));
this.setMirror(stack, mode, Mirror.NONE);
}
}
}
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 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>();
}
/**
* 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;
}
}
/**
* 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;
}
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
}