下面列出了net.minecraft.util.EnumFacing#Axis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Sets the freshly placed TileEntityGrate's orientation.
*
* @param grate the grate in question.
* @param hitX the hit x-coordinate.
* @param hitY the hit y-coordinate.
* @param hitZ the hit z-coordinate.
* @param axis the axis the block is on.
*/
private static void setOffsetOrientation(TileEntityGrate grate, float hitX, float hitY, float hitZ, EnumFacing.Axis axis) {
// Set the grate's axis.
grate.setAxis(axis);
// Resolve the hit value.
final float hit = getAxialValue(axis, hitX, hitY, hitZ);
// Set the grate's offset.
if (hit <= 0.3333F) {
grate.setOffset(TileEntityGrate.EnumOffset.NEAR);
} else if (hit <= 0.6666F) {
grate.setOffset(TileEntityGrate.EnumOffset.CENTER);
} else {
grate.setOffset(TileEntityGrate.EnumOffset.FAR);
}
}
@SideOnly(Side.CLIENT)
public static PropertyItem.PItem getDisplayItem(ItemStack stack, World world, EntityLivingBase entity, float x, float z, EnumFacing.Axis axis) {
if(stack == null)
return null;
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack, world, entity);
if(model == null || model.isBuiltInRenderer()) {
// missing model so people don't go paranoid when their chests go missing
model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getMissingModel();
}
float rotation = 0;
if(axis == EnumFacing.Axis.X)
{
rotation = (float)Math.PI /2f;
}
PropertyItem.PItem item = new PropertyItem.PItem(model, x,0,z, 0.45f, axis == EnumFacing.Axis.X ? (float) (Math.PI/2f) : 0);
if(stack.getItem() instanceof ItemBlock) {
item.y = -0.3125f;
item.s = 0.375f;
item.r = 0;
}
return item;
}
@SubscribeEvent
public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
EntityLivingBase entity = event.getEntityLiving();
if (entity.world.isRemote) {
return;
}
if (entity.collidedHorizontally && isBeingPushedByPiston(entity)) {
Squashable squashable = entity.getCapability(squashableCap(), null);
if (squashable == null) {
return;
}
double[] pistonDeltas = getPistonDeltas(entity);
double pushedAngle = Math.atan2(pistonDeltas[2], pistonDeltas[0]);
EnumFacing.Axis faceAxis = EnumFacing.fromAngle(entity.rotationYaw).getAxis();
EnumFacing.Axis pushAxis = EnumFacing.fromAngle(pushedAngle).getAxis();
EnumFacing.Axis squashAxis = faceAxis == pushAxis ? EnumFacing.Axis.Z : EnumFacing.Axis.X;
squashable.squash(squashAxis);
NETWORK.sendToAllTracking(new SquashEntityMessage(entity, squashAxis), entity);
}
}
@Override
protected void renderWorldBlockWoodStatic(ITessellator tess, IExtendedBlockState state, BlockGrate block, EnumFacing side, TextureAtlasSprite sprite) {
// Setup
final TileEntityGrate.EnumOffset offset = AgriProperties.OFFSET.getValue(state);
final EnumFacing.Axis axis = AgriProperties.AXIS.getValue(state);
// Rotate
RenderUtilBase.rotateBlock(tess, EnumFacing.getFacingFromAxis(EnumFacing.AxisDirection.POSITIVE, axis));
// Offset
tess.translate(0, 0, offset.getOffset());
// Draw Grate
tess.drawScaledPrism(1, 0, 0, 3, 16, 2, sprite);
tess.drawScaledPrism(5, 0, 0, 7, 16, 2, sprite);
tess.drawScaledPrism(9, 0, 0, 11, 16, 2, sprite);
tess.drawScaledPrism(13, 0, 0, 15, 16, 2, sprite);
tess.drawScaledPrism(0, 1, 0, 16, 3, 2, sprite);
tess.drawScaledPrism(0, 5, 0, 16, 7, 2, sprite);
tess.drawScaledPrism(0, 9, 0, 16, 11, 2, sprite);
tess.drawScaledPrism(0, 13, 0, 16, 15, 2, sprite);
}
public static EnumFacing[] getSidesForAxis(EnumFacing.Axis axis)
{
if (axis == EnumFacing.Axis.X)
{
return ADJACENT_SIDES_ZY;
}
return axis == EnumFacing.Axis.Z ? ADJACENT_SIDES_XY : ADJACENT_SIDES_XZ;
}
public static EnumAxis fromFacingAxis(EnumFacing.Axis axis)
{
switch (axis)
{
case X:
return X;
case Y:
return Y;
case Z:
return Z;
default:
return NONE;
}
}
@Override
public void fromBytes(ByteBuf buf) {
this.entityId = buf.readInt();
EnumFacing.Axis[] values = EnumFacing.Axis.values();
this.axis = values[buf.readByte() % values.length];
}
public void setAxis(@Nonnull EnumFacing.Axis axis) {
// Validate.
Preconditions.checkNotNull(axis);
// Set.
if (this.axis != axis) {
this.axis = axis;
this.markForUpdate();
}
}
private static float getAxialValue(@Nonnull EnumFacing.Axis axis, float x, float y, float z) {
switch (axis) {
case X:
return x;
case Y:
return y;
case Z:
return z;
default:
throw new NullPointerException();
}
}
protected void countBlocksInChunkRespectingLayerRange(ChunkPos pos, LayerRange range)
{
EnumFacing.Axis axis = range.getAxis();
BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos();
for (IntBoundingBox bb : this.getBoxesInChunk(pos))
{
final int startX = axis == EnumFacing.Axis.X ? Math.max(bb.minX, range.getLayerMin()) : bb.minX;
final int startY = axis == EnumFacing.Axis.Y ? Math.max(bb.minY, range.getLayerMin()) : bb.minY;
final int startZ = axis == EnumFacing.Axis.Z ? Math.max(bb.minZ, range.getLayerMin()) : bb.minZ;
final int endX = axis == EnumFacing.Axis.X ? Math.min(bb.maxX, range.getLayerMax()) : bb.maxX;
final int endY = axis == EnumFacing.Axis.Y ? Math.min(bb.maxY, range.getLayerMax()) : bb.maxY;
final int endZ = axis == EnumFacing.Axis.Z ? Math.min(bb.maxZ, range.getLayerMax()) : bb.maxZ;
for (int y = startY; y <= endY; ++y)
{
for (int z = startZ; z <= endZ; ++z)
{
for (int x = startX; x <= endX; ++x)
{
posMutable.setPos(x, y, z);
this.countAtPosition(posMutable);
}
}
}
}
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
EnumFacing.Axis enumfacing$axis = state.getValue(FACING).getAxis();
if (enumfacing$axis == EnumFacing.Axis.Z && (canFenceGateConnectTo(worldIn, pos, EnumFacing.WEST) || canFenceGateConnectTo(worldIn, pos, EnumFacing.EAST)) || enumfacing$axis == EnumFacing.Axis.X && (canFenceGateConnectTo(worldIn, pos, EnumFacing.NORTH) || canFenceGateConnectTo(worldIn, pos, EnumFacing.SOUTH)))
{
state = state.withProperty(IN_WALL, Boolean.TRUE);
}
return state;
}
public EnumFacing.Axis getRotation() {
return rotation;
}
public FlattenedModel(ModelBase wrapped, EnumFacing.Axis squashedAxis) {
this.wrapped = wrapped;
this.squashedAxis = squashedAxis;
}
@Override
public void render(TileEntityRotationAxle tileentity, double x, double y, double z,
float partialTick, int destroyStage, float alpha) {
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
GlStateManager.pushMatrix();
GlStateManager.disableLighting();
GlStateManager.translate(x, y, z);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
int brightness = tileentity.getWorld().getCombinedLight(tileentity.getPos(), 0);
IBlockState gearState = Minecraft.getMinecraft().world.getBlockState(tileentity.getPos());
if (gearState.getBlock() instanceof BlockRotationAxle) {
EnumFacing.Axis facingAxis = gearState.getValue(BlockRotationAxle.AXIS);
GlStateManager.translate(0.5, 0.5, 0.5);
switch (facingAxis) {
case X:
// Rotates (1, 0, 0) -> (1, 0, 0)
break;
case Y:
// Rotates (1, 0, 0) -> (0, 1, 0)
GL11.glRotated(90, 0, 0, 1);
break;
case Z:
// Rotates (1, 0, 0) -> (0, 0, 1)
GL11.glRotated(-90, 0, 1, 0);
break;
}
GL11.glRotated(Math.toDegrees(tileentity.getRenderRotationRadians(partialTick)), 1, 0,
0);
GlStateManager.translate(-0.5, -0.5, -0.5);
}
double keyframe = 1;
GibsAnimationRegistry.getAnimation("rotation_axle")
.renderAnimation(keyframe, brightness);
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.resetColor();
}
public void setRotation(EnumFacing.Axis axis)
{
rotation = axis;
}
@Nullable
public EnumFacing.Axis getSquashedAxis() {
return this.squashedAxis;
}
public TileEntityRotationAxle(EnumFacing.Axis axleAxis) {
super();
setAxleAxis(axleAxis);
}
protected void renderOverlayReducedEdges(BlockPos pos, OverlayType[][][] adjTypes, OverlayType typeSelf, Color4f overlayColor, BufferBuilder bufferOverlayOutlines)
{
OverlayType[] neighborTypes = new OverlayType[4];
Vec3i[] neighborPositions = new Vec3i[4];
int lines = 0;
for (EnumFacing.Axis axis : PositionUtils.AXES_ALL)
{
for (int corner = 0; corner < 4; ++corner)
{
Vec3i[] offsets = PositionUtils.getEdgeNeighborOffsets(axis, corner);
int index = -1;
boolean hasCurrent = false;
// Find the position(s) around a given edge line that have the shared greatest rendering priority
for (int i = 0; i < 4; ++i)
{
Vec3i offset = offsets[i];
OverlayType type = adjTypes[offset.getX() + 1][offset.getY() + 1][offset.getZ() + 1];
// type NONE
if (type == OverlayType.NONE)
{
continue;
}
// First entry, or sharing at least the current highest found priority
if (index == -1 || type.getRenderPriority() >= neighborTypes[index - 1].getRenderPriority())
{
// Actually a new highest priority, add it as the first entry and rewind the index
if (index < 0 || type.getRenderPriority() > neighborTypes[index - 1].getRenderPriority())
{
index = 0;
}
// else: Same priority as a previous entry, append this position
//System.out.printf("plop 0 axis: %s, corner: %d, i: %d, index: %d, type: %s\n", axis, corner, i, index, type);
neighborPositions[index] = new Vec3i(pos.getX() + offset.getX(), pos.getY() + offset.getY(), pos.getZ() + offset.getZ());
neighborTypes[index] = type;
// The self position is the first (offset = [0, 0, 0]) in the arrays
hasCurrent |= (i == 0);
++index;
}
}
//System.out.printf("plop 1 index: %d, pos: %s\n", index, pos);
// Found something to render, and the current block is among the highest priority for this edge
if (index > 0 && hasCurrent)
{
Vec3i posTmp = new Vec3i(pos.getX(), pos.getY(), pos.getZ());
int ind = -1;
for (int i = 0; i < index; ++i)
{
Vec3i tmp = neighborPositions[i];
//System.out.printf("posTmp: %s, tmp: %s\n", posTmp, tmp);
// Just prioritize the position to render a shared highest priority edge by the coordinates
if (tmp.getX() <= posTmp.getX() && tmp.getY() <= posTmp.getY() && tmp.getZ() <= posTmp.getZ())
{
posTmp = tmp;
ind = i;
}
}
// The current position is the one that should render this edge
if (posTmp.getX() == pos.getX() && posTmp.getY() == pos.getY() && posTmp.getZ() == pos.getZ())
{
//System.out.printf("plop 2 index: %d, ind: %d, pos: %s, off: %s\n", index, ind, pos, posTmp);
RenderUtils.drawBlockBoxEdgeBatchedLines(pos, axis, corner, overlayColor, bufferOverlayOutlines);
lines++;
}
}
}
}
//System.out.printf("typeSelf: %s, pos: %s, lines: %d\n", typeSelf, pos, lines);
}
private boolean walkFrameLoop(BlockPos pos, EnumFacing.Axis axis, EnumFacing frameSide, int distanceLimit)
{
int counter = 0;
int turns = 0;
int tries = 0;
IBlockState state;
Block block;
BlockPos startPos = pos;
BlockPos posLast = startPos;
EnumFacing firstTrySide = frameSide;
EnumFacing moveDirection = frameSide;
while (counter < distanceLimit)
{
moveDirection = firstTrySide;
for (tries = 0; tries < 4; tries++)
{
pos = posLast.offset(moveDirection);
state = this.world.getBlockState(pos);
block = state.getBlock();
if (block.isAir(state, this.world, pos))
{
posLast = pos;
// The firstTrySide is facing into the adjacent portal frame when traveling
// along a straight frame. Thus we need to rotate it once to keep going straight.
// If we need to rotate it more than once, then we have hit a "right hand corner".
if (tries > 1)
{
turns++;
}
// If we didn't have to rotate the firstTrySide at all, then we hit a "left hand turn"
// ie. traveled through an outer bend.
else if (tries == 0)
{
turns--;
}
// Set the firstTrySide one rotation back from the side that we successfully moved to
// so that we can go around possible outer bends.
firstTrySide = moveDirection.rotateAround(axis).getOpposite();
break;
}
// Found a portal frame block, try the next adjacent side...
else if (block == this.blockFrame)
{
moveDirection = moveDirection.rotateAround(axis);
}
// Found a non-air, non-portal-frame block -> invalid area.
else
{
return false;
}
}
// If we can return to the starting position hugging the portal frame,
// then this is a valid portal frame loop.
// Note that it is only valid if it forms an inside area, thus the turns check.
// the tries == 4 && counter == 0 check is for a 1x1 area special case
if ((tries == 4 && counter == 0) || pos.equals(startPos))
{
return turns >= 0;
}
counter++;
}
return false;
}
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
EnumFacing.Axis enumfacing$axis = state.getValue(AXIS);
if (enumfacing$axis == EnumFacing.Axis.X) {
Size blockportal$size = new Size(worldIn, pos, EnumFacing.Axis.X);
if (!blockportal$size.isValid() ||
blockportal$size.portalBlockCount < blockportal$size.width * blockportal$size.height) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}
} else if (enumfacing$axis == EnumFacing.Axis.Z) {
Size blockportal$size1 = new Size(worldIn, pos, EnumFacing.Axis.Z);
if (!blockportal$size1.isValid() ||
blockportal$size1.portalBlockCount < blockportal$size1.width * blockportal$size1.height) {
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}