fix clipboard rotation

This commit is contained in:
Sen 2025-06-26 18:07:57 +02:00
parent 66d1b9befe
commit 1c6939d61f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
13 changed files with 252 additions and 1243 deletions

View file

@ -9,22 +9,18 @@ import common.model.Model;
import common.model.ModelProvider;
import common.model.ModelRotation;
import common.properties.Property;
import common.properties.PropertyEnum;
import common.util.BlockPos;
import common.util.Facing;
import common.util.Identifyable;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;
public class BlockLog extends BlockRotatedPillar
{
public static final PropertyEnum<BlockLog.EnumAxis> LOG_AXIS = PropertyEnum.<BlockLog.EnumAxis>create("axis", BlockLog.EnumAxis.class);
public BlockLog()
{
super(Material.WOOD);
this.setDefaultState(this.getBaseState().withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
this.setDefaultState(this.getBaseState().withProperty(AXIS, Facing.Axis.Y));
this.setTab(CheatTab.WOOD);
this.setHardness(2.0F);
this.setStepSound(SoundType.WOOD);
@ -33,34 +29,30 @@ public class BlockLog extends BlockRotatedPillar
public void onBlockRemoved(AWorldServer worldIn, BlockPos pos, State state)
{
int i = 4;
int j = i + 1;
int r = 4;
int l = r + 1;
if (worldIn.isAreaLoaded(pos.add(-j, -j, -j), pos.add(j, j, j)))
if (worldIn.isAreaLoaded(pos.add(-l, -l, -l), pos.add(l, l, l)))
{
for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-i, -i, -i), pos.add(i, i, i)))
for (BlockPos bpos : BlockPos.getAllInBox(pos.add(-r, -r, -r), pos.add(r, r, r)))
{
State iblockstate = worldIn.getState(blockpos);
State blk = worldIn.getState(bpos);
if (iblockstate.getBlock().getMaterial() == Material.LEAVES && !((Boolean)iblockstate.getValue(BlockLeaves.DECAY)).booleanValue())
if (blk.getBlock().getMaterial() == Material.LEAVES && !((Boolean)blk.getValue(BlockLeaves.DECAY)).booleanValue())
{
worldIn.setState(blockpos, iblockstate.withProperty(BlockLeaves.DECAY, Boolean.valueOf(true)), 4);
worldIn.setState(bpos, blk.withProperty(BlockLeaves.DECAY, Boolean.valueOf(true)), 4);
}
}
}
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer)
{
return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, placer).withProperty(LOG_AXIS, BlockLog.EnumAxis.fromFacingAxis(facing.getAxis()));
return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, placer).withProperty(AXIS, facing.getAxis());
}
public Model getModel(ModelProvider provider, String name, State state) {
switch(state.getValue(LOG_AXIS)) {
switch(state.getValue(AXIS)) {
case X:
return provider.getModel(name + "_bark").add().d().rot(180).u()
.n(name + "_top").rot(180).s(name + "_top").w().rot(270)
@ -72,114 +64,51 @@ public class BlockLog extends BlockRotatedPillar
return provider.getModel(name + "_bark").add().d().rot(180).u()
.n(name + "_top").rot(180).s(name + "_top").w().rot(270)
.e().rot(90);
case NONE:
return provider.getModel(name + "_bark").add().all();
}
}
public State getStateFromMeta(int meta)
{
State iblockstate = this.getState();
State state = this.getState();
switch (meta & 3)
{
default:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
state = state.withProperty(AXIS, Facing.Axis.Y);
break;
case 1:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
state = state.withProperty(AXIS, Facing.Axis.X);
break;
case 2:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
state = state.withProperty(AXIS, Facing.Axis.Z);
break;
case 3:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
}
return iblockstate;
return state;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(State state)
{
int i = 0;
int meta = 0;
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
switch ((Facing.Axis)state.getValue(AXIS))
{
case X:
i = 1;
meta = 1;
break;
case Z:
i = 2;
meta = 2;
break;
case NONE:
i = 3;
}
return i;
return meta;
}
protected Property[] getProperties()
{
return new Property[] {LOG_AXIS};
}
public static enum EnumAxis implements Identifyable
{
X("x", Facing.Axis.X),
Y("y", Facing.Axis.Y),
Z("z", Facing.Axis.Z),
NONE("none", null);
private final String name;
private final Facing.Axis axis;
private EnumAxis(String name, Facing.Axis axis)
{
this.name = name;
this.axis = axis;
}
public String toString()
{
return this.name;
}
public static BlockLog.EnumAxis fromFacingAxis(Facing.Axis axis)
{
switch (axis)
{
case X:
return X;
case Y:
return Y;
case Z:
return Z;
default:
return NONE;
}
}
public String getName()
{
return this.name;
}
public Facing.Axis getAxis()
{
return this.axis;
}
return new Property[] {AXIS};
}
}

View file

@ -16,6 +16,7 @@ import common.properties.PropertyBool;
import common.properties.PropertyEnum;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.DirectionVec;
import common.util.Facing;
import common.util.Identifyable;
import common.world.IWorldAccess;
@ -322,7 +323,7 @@ public class BlockLever extends Block
return new ItemBlock(this, "lever", false);
}
public static enum EnumOrientation implements Identifyable
public static enum EnumOrientation implements Identifyable, DirectionVec<EnumOrientation>
{
DOWN_X(0, "down_x", Facing.DOWN),
EAST(1, "east", Facing.EAST),
@ -422,6 +423,18 @@ public class BlockLever extends Block
return this.name;
}
public Facing getVector() {
return this == DOWN_Z || this == UP_Z ? Facing.SOUTH : (this == DOWN_X || this == UP_X ? Facing.EAST : this.facing);
}
public boolean isAxis() {
return this.facing.getAxis().isVertical();
}
public boolean canApply(EnumOrientation dir) {
return this.facing.getAxis().isVertical() == dir.facing.getAxis().isVertical();
}
static {
for (BlockLever.EnumOrientation blocklever$enumorientation : values())
{

View file

@ -14,6 +14,7 @@ import common.model.ModelRotation;
import common.properties.Property;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.DirectionVec;
import common.util.Facing;
import common.util.HitPosition;
import common.util.Identifyable;
@ -229,30 +230,36 @@ public abstract class BlockRailBase extends Block
}
public abstract Property<BlockRailBase.EnumRailDirection> getShapeProperty();
private static enum BaseShape {
STRAIGHT, ASCENDING, TURNED;
}
public static enum EnumRailDirection implements Identifyable
public static enum EnumRailDirection implements Identifyable, DirectionVec<EnumRailDirection>
{
NORTH_SOUTH(0, "north_south", Facing.SOUTH),
EAST_WEST(1, "east_west", Facing.EAST),
ASCENDING_EAST(2, "ascending_east", Facing.EAST),
ASCENDING_WEST(3, "ascending_west", Facing.WEST),
ASCENDING_NORTH(4, "ascending_north", Facing.NORTH),
ASCENDING_SOUTH(5, "ascending_south", Facing.DOWN),
SOUTH_EAST(6, "south_east", Facing.EAST),
SOUTH_WEST(7, "south_west", Facing.SOUTH),
NORTH_WEST(8, "north_west", Facing.NORTH),
NORTH_EAST(9, "north_east", Facing.WEST);
NORTH_SOUTH(0, "north_south", Facing.SOUTH, BaseShape.STRAIGHT),
EAST_WEST(1, "east_west", Facing.EAST, BaseShape.STRAIGHT),
ASCENDING_EAST(2, "ascending_east", Facing.EAST, BaseShape.ASCENDING),
ASCENDING_WEST(3, "ascending_west", Facing.WEST, BaseShape.ASCENDING),
ASCENDING_NORTH(4, "ascending_north", Facing.NORTH, BaseShape.ASCENDING),
ASCENDING_SOUTH(5, "ascending_south", Facing.DOWN, BaseShape.ASCENDING),
SOUTH_EAST(6, "south_east", Facing.EAST, BaseShape.TURNED),
SOUTH_WEST(7, "south_west", Facing.SOUTH, BaseShape.TURNED),
NORTH_WEST(8, "north_west", Facing.NORTH, BaseShape.TURNED),
NORTH_EAST(9, "north_east", Facing.WEST, BaseShape.TURNED);
private static final BlockRailBase.EnumRailDirection[] META_LOOKUP = new BlockRailBase.EnumRailDirection[values().length];
private final int meta;
private final String name;
private final Facing facing;
private final BaseShape shape;
private EnumRailDirection(int meta, String name, Facing facing)
private EnumRailDirection(int meta, String name, Facing facing, BaseShape shape)
{
this.meta = meta;
this.name = name;
this.facing = facing;
this.shape = shape;
}
public int getMetadata()
@ -290,6 +297,18 @@ public abstract class BlockRailBase extends Block
return this.facing;
}
public Facing getVector() {
return this.facing;
}
public boolean isAxis() {
return false;
}
public boolean canApply(EnumRailDirection dir) {
return this.shape == dir.shape;
}
static {
for (BlockRailBase.EnumRailDirection blockrailbase$enumraildirection : values())
{

View file

@ -0,0 +1,9 @@
package common.util;
public interface DirectionVec<T> {
public Facing getVector();
public boolean isAxis();
default boolean canApply(T other) {
return true;
}
}

View file

@ -8,7 +8,7 @@ import common.collect.Iterators;
import common.collect.Maps;
import common.rng.Random;
public enum Facing implements Identifyable
public enum Facing implements Identifyable, DirectionVec<Facing>
{
DOWN(0, 2, 1, -1, "down", Facing.AxisDirection.NEGATIVE, Facing.Axis.Y, new Vec3i(0, -1, 0)),
UP(1, 3, 0, -1, "up", Facing.AxisDirection.POSITIVE, Facing.Axis.Y, new Vec3i(0, 1, 0)),
@ -353,6 +353,14 @@ public enum Facing implements Identifyable
{
return this.directionVec;
}
public Facing getVector() {
return this.axis.isVertical() ? null : this;
}
public boolean isAxis() {
return false;
}
static {
for (Facing enumfacing : values())
@ -368,7 +376,7 @@ public enum Facing implements Identifyable
}
}
public static enum Axis implements Predicate<Facing>, Identifyable {
public static enum Axis implements Predicate<Facing>, Identifyable, DirectionVec<Axis> {
X("x", Facing.Plane.HORIZONTAL),
Y("y", Facing.Plane.VERTICAL),
Z("z", Facing.Plane.HORIZONTAL);
@ -422,6 +430,14 @@ public enum Facing implements Identifyable
{
return this.name;
}
public Facing getVector() {
return this == Y ? null : (this == X ? EAST : SOUTH);
}
public boolean isAxis() {
return true;
}
static {
for (Facing.Axis enumfacing$axis : values())