Fix animated torch not animating smoothly when toggled serverside (bursts and hourglass)

This commit is contained in:
Vincent Lee committed 2017-03-17 11:18:32 -05:00
1 parent 8529cd2ae9
commit 78610b2d59
1 file changed
+19 -12
@@ -21,6 +21,7 @@ import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.common.block.ModBlocks;
public class TileAnimatedTorch extends TileMod {
@@ -57,13 +58,13 @@ public class TileAnimatedTorch extends TileMod {
}
public void handRotate() {
rotateTo((side + 1) % 4);
if(!world.isRemote)
world.addBlockEvent(getPos(), ModBlocks.animatedTorch, 0, (side + 1) % 4);
}
public void toggle() {
rotateTo(torchMode.modeSwitcher.rotate(this, side));
if(!world.isRemote) {
world.addBlockEvent(getPos(), ModBlocks.animatedTorch, 0, torchMode.modeSwitcher.rotate(this, side));
nextRandomRotation = world.rand.nextInt(4);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
@@ -71,16 +72,22 @@ public class TileAnimatedTorch extends TileMod {
public void onWanded() {
int modeOrdinal = torchMode.ordinal();
TorchMode[] modes = TorchMode.class.getEnumConstants();
TorchMode[] modes = TorchMode.values();
modeOrdinal++;
if(modeOrdinal >= modes.length)
modeOrdinal = 0;
torchMode = modes[modeOrdinal];
torchMode = modes[(modeOrdinal + 1) % modes.length];
}
public void rotateTo(int side) {
@Override
public boolean receiveClientEvent(int id, int param) {
if (id == 0) {
rotateTo(param);
return true;
} else {
return super.receiveClientEvent(id, param);
}
}
private void rotateTo(int side) {
if(rotating)
return;
@@ -151,8 +158,8 @@ public class TileAnimatedTorch extends TileMod {
nextRandomRotation = cmp.getInteger(TAG_NEXT_RANDOM_ROTATION);
int modeOrdinal = cmp.getInteger(TAG_TORCH_MODE);
TorchMode[] modes = TorchMode.class.getEnumConstants();
torchMode = modes[Math.max(0, Math.min(modes.length - 1, modeOrdinal))];
TorchMode[] modes = TorchMode.values();
torchMode = modes[modeOrdinal % modes.length];
}
public static enum TorchMode {