Skip to content

Commit ce4ef95

Browse files
committed
Merge remote-tracking branch 'origin/mc-1.10.2' into mc-1.11.2
# Conflicts: # src/main/java/mods/timberjack/common/entity/EntityTimber.java # src/main/java/mods/timberjack/common/felling/TimberjackEventHandler.java
2 parents ce061b1 + 191819f commit ce4ef95

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/main/java/mods/timberjack/common/entity/EntityTimber.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class EntityTimber extends Entity implements IEntityAdditionalSpawnData {
5252
private float fallHurtAmount = 2.0F;
5353
private NBTTagCompound tileEntityData;
5454
private List<ItemStack> drops = new ArrayList<>();
55-
private EnumFacing fellingDirection;
55+
private EnumFacing fellingDirection = EnumFacing.UP;
5656

5757
public EntityTimber(World worldIn) {
5858
super(worldIn);
@@ -124,7 +124,7 @@ public void onUpdate() {
124124

125125
IBlockState state = this.world.getBlockState(currentPos);
126126
if (state.getBlock() == block) {
127-
if (!log) {
127+
if (!this.world.isRemote && !log) {
128128
drops.addAll(block.getDrops(world, currentPos, state, 0));
129129
}
130130
this.world.setBlockToAir(currentPos);
@@ -261,7 +261,7 @@ private boolean doTileDrops() {
261261
return world.getGameRules().getBoolean("doEntityDrops");
262262
}
263263

264-
public void rotateLog(IBlockState state, BlockPos pos) {
264+
private void rotateLog(IBlockState state, BlockPos pos) {
265265
if (state.getBlock() instanceof BlockLog && state.getProperties().containsKey(BlockLog.LOG_AXIS)) {
266266
BlockLog.EnumAxis axis;
267267
switch (fellingDirection.getAxis()) {
@@ -274,8 +274,10 @@ public void rotateLog(IBlockState state, BlockPos pos) {
274274
default:
275275
axis = BlockLog.EnumAxis.Y;
276276
}
277-
IBlockState newState = state.withProperty(BlockLog.LOG_AXIS, axis);
278-
world.setBlockState(pos, newState);
277+
if (axis != BlockLog.EnumAxis.Y) {
278+
IBlockState newState = state.withProperty(BlockLog.LOG_AXIS, axis);
279+
world.setBlockState(pos, newState);
280+
}
279281
}
280282
}
281283

@@ -292,7 +294,7 @@ protected void writeEntityToNBT(NBTTagCompound compound) {
292294
compound.setBoolean("HurtEntities", this.hurtEntities);
293295
compound.setFloat("FallHurtAmount", this.fallHurtAmount);
294296
compound.setInteger("FallHurtMax", this.fallHurtMax);
295-
compound.setInteger("FallingDirection", this.fellingDirection.ordinal());
297+
compound.setInteger("FellingDirection", this.fellingDirection.ordinal());
296298

297299
if (this.tileEntityData != null) {
298300
compound.setTag("TileEntityData", this.tileEntityData);
@@ -330,7 +332,7 @@ protected void readEntityFromNBT(NBTTagCompound compound) {
330332
this.tileEntityData = compound.getCompoundTag("TileEntityData");
331333
}
332334

333-
this.fellingDirection = EnumFacing.VALUES[compound.getInteger("FallingDirection")];
335+
this.fellingDirection = EnumFacing.VALUES[compound.getInteger("FellingDirection")];
334336

335337
if (block == null || block.getDefaultState().getMaterial() == Material.AIR) {
336338
this.fallingBlock = Blocks.LOG.getDefaultState();
@@ -371,10 +373,14 @@ public boolean ignoreItemEntityData() {
371373
@Override
372374
public void writeSpawnData(ByteBuf buffer) {
373375
buffer.writeInt(Block.getStateId(fallingBlock));
376+
buffer.writeBoolean(log);
377+
buffer.writeByte(fellingDirection.ordinal());
374378
}
375379

376380
@Override
377381
public void readSpawnData(ByteBuf additionalData) {
378-
fallingBlock = Block.getStateById(additionalData.getInt(additionalData.readerIndex()) & 65535);
382+
fallingBlock = Block.getStateById(additionalData.readInt() & 65535);
383+
log = additionalData.readBoolean();
384+
fellingDirection = EnumFacing.VALUES[additionalData.readByte()];
379385
}
380386
}

src/main/java/mods/timberjack/common/felling/TimberjackEventHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ public void chopEvent(BlockEvent.BreakEvent event) {
7171
if ((!event.getPlayer().isSneaking() || !TimberjackConfig.sneakingPreventsFelling()) && TimberjackUtils.isWood(event.getState(), world, event.getPos())) {
7272
EnumFacing fellingDirection;
7373
if (world.rand.nextFloat() < 0.1) {
74-
fellingDirection = EnumFacing.HORIZONTALS[new Random().nextInt(EnumFacing.HORIZONTALS.length)];
74+
fellingDirection = getRandomHorizontalFacing();
7575
} else {
7676
fellingDirection = EnumFacing.getDirectionFromEntityLiving(event.getPos(), event.getPlayer()).getOpposite();
77+
if (fellingDirection.getAxis() == EnumFacing.Axis.Y)
78+
fellingDirection = getRandomHorizontalFacing();
7779
}
7880
FellingManager.fellingManagers.computeIfAbsent(world, FellingManager::new).onChop(event.getPos(), fellingDirection);
7981
}
8082
}
83+
84+
private EnumFacing getRandomHorizontalFacing() {
85+
return EnumFacing.HORIZONTALS[new Random().nextInt(EnumFacing.HORIZONTALS.length)];
86+
}
8187
}

src/main/java/mods/timberjack/common/felling/TimberjackUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ private static void spawnFalling(World world, BlockPos pos, Vec3d centroid, IBlo
113113
Vec3d vector = new Vec3d(pos.getX(), 0, pos.getZ());
114114
vector = vector.subtract(centroid.xCoord, 0, centroid.zCoord);
115115
vector = vector.normalize().scale(0.5);
116-
vector = vector.add(new Vec3d(fellingDirection.getDirectionVec()));
116+
if (fellingDirection.getAxis() != EnumFacing.Axis.Y)
117+
vector = vector.add(new Vec3d(fellingDirection.getDirectionVec()));
117118
vector = vector.normalize();
118119
entity.motionX = vector.xCoord * 0.3 + (world.rand.nextFloat() - 0.5) * 0.15;
119120
entity.motionZ = vector.zCoord * 0.3 + (world.rand.nextFloat() - 0.5) * 0.15;

0 commit comments

Comments
 (0)