diff --git a/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java b/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java index b52aec2cd..b6a21cafb 100644 --- a/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java +++ b/src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java @@ -60,6 +60,8 @@ import vazkii.botania.common.core.handler.MethodHandles; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.item.ItemManaTablet; import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.network.PacketBotaniaEffect; +import vazkii.botania.common.network.PacketHandler; import java.awt.*; import java.util.List; @@ -80,25 +82,25 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc private static final String TAG_INPUT_KEY = "inputKey"; private static final String TAG_OUTPUT_KEY = "outputKey"; - boolean outputting = false; + private boolean outputting = false; public EnumDyeColor color = EnumDyeColor.WHITE; int mana; - int knownMana = -1; + private int knownMana = -1; public int manaCap = -1; - int soundTicks = 0; - boolean canAccept = true; - boolean canSpare = true; + private int soundTicks = 0; + private boolean canAccept = true; + private boolean canSpare = true; public boolean fragile = false; - public boolean isDoingTransfer = false; - public int ticksDoingTransfer = 0; + boolean isDoingTransfer = false; + int ticksDoingTransfer = 0; - String inputKey = ""; - String outputKey = ""; + private String inputKey = ""; + private String outputKey = ""; - int ticks = 0; - boolean sendPacket = false; + private int ticks = 0; + private boolean sendPacket = false; @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) { @@ -135,7 +137,7 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc } public boolean collideEntityItem(EntityItem item) { - if(item.isDead) + if(worldObj.isRemote || item.isDead) return false; boolean didChange = false; @@ -163,18 +165,16 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc if(getCurrentMana() >= mana) { recieveMana(-mana); - if(!worldObj.isRemote) { - stack.stackSize--; - if(stack.stackSize == 0) - item.setDead(); + stack.stackSize--; + if(stack.stackSize == 0) + item.setDead(); - ItemStack output = recipe.getOutput().copy(); - EntityItem outputItem = new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output); - try { - MethodHandles.itemAge_setter.invokeExact(outputItem, 105); - } catch (Throwable ignored) {} - worldObj.spawnEntityInWorld(outputItem); - } + ItemStack output = recipe.getOutput().copy(); + EntityItem outputItem = new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, output); + try { + MethodHandles.itemAge_setter.invokeExact(outputItem, 105); + } catch (Throwable ignored) {} + worldObj.spawnEntityInWorld(outputItem); craftingFanciness(); didChange = true; @@ -187,38 +187,37 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc return didChange; } - public void craftingFanciness() { + private void craftingFanciness() { if(soundTicks == 0) { worldObj.playSound(null, pos, BotaniaSoundEvents.manaPoolCraft, SoundCategory.BLOCKS, 0.4F, 4F); soundTicks = 6; } - for(int i = 0; i < 25; i++) { - float red = (float) Math.random(); - float green = (float) Math.random(); - float blue = (float) Math.random(); - Botania.proxy.sparkleFX(worldObj, pos.getX() + 0.5 + Math.random() * 0.4 - 0.2, pos.getY() + 1, pos.getZ() + 0.5 + Math.random() * 0.4 - 0.2, red, green, blue, (float) Math.random(), 10); - } + PacketHandler.sendToNearby(worldObj, getPos(), + new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.POOL_CRAFT, pos.getX(), pos.getY(), pos.getZ())); } @Override public void updateEntity() { - boolean wasDoingTransfer = isDoingTransfer; - isDoingTransfer = false; if(manaCap == -1) manaCap = worldObj.getBlockState(getPos()).getValue(BotaniaStateProps.POOL_VARIANT) == PoolVariant.DILUTED ? MAX_MANA_DILLUTED : MAX_MANA; if(!ManaNetworkHandler.instance.isPoolIn(this) && !isInvalid()) ManaNetworkEvent.addPool(this); - if(soundTicks > 0) - soundTicks--; - if(worldObj.isRemote) { double particleChance = 1F - (double) getCurrentMana() / (double) manaCap * 0.1; Color color = new Color(0x00C6FF); if(Math.random() > particleChance) Botania.proxy.wispFX(worldObj, pos.getX() + 0.3 + Math.random() * 0.5, pos.getY() + 0.6 + Math.random() * 0.25, pos.getZ() + Math.random(), color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, (float) Math.random() / 3F, (float) -Math.random() / 25F, 2F); + return; + } + + boolean wasDoingTransfer = isDoingTransfer; + isDoingTransfer = false; + + if(soundTicks > 0) { + soundTicks--; } if(sendPacket && ticks % 10 == 0) { @@ -252,8 +251,7 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc didSomething = true; int manaVal = Math.min(transfRate, Math.min(getCurrentMana(), mana.getMaxMana(stack) - mana.getMana(stack))); - if(!worldObj.isRemote) - mana.addMana(stack, manaVal); + mana.addMana(stack, manaVal); recieveMana(-manaVal); } } else { @@ -262,17 +260,15 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc didSomething = true; int manaVal = Math.min(transfRate, Math.min(manaCap - getCurrentMana(), mana.getMana(stack))); - if(!worldObj.isRemote) - mana.addMana(stack, -manaVal); + mana.addMana(stack, -manaVal); recieveMana(manaVal); } } if(didSomething) { - if(worldObj.isRemote && ConfigHandler.chargingAnimationEnabled && worldObj.rand.nextInt(20) == 0) { - Vector3 itemVec = Vector3.fromTileEntity(this).add(0.5, 0.5 + Math.random() * 0.3, 0.5); - Vector3 tileVec = Vector3.fromTileEntity(this).add(0.2 + Math.random() * 0.6, 0, 0.2 + Math.random() * 0.6); - LightningHandler.spawnLightningBolt(worldObj, outputting ? tileVec : itemVec, outputting ? itemVec : tileVec, 80, worldObj.rand.nextLong(), 0x4400799c, 0x4400C6FF); + if(ConfigHandler.chargingAnimationEnabled && worldObj.rand.nextInt(20) == 0) { + PacketHandler.sendToNearby(worldObj, getPos(), + new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.POOL_CHARGE, getPos().getX(), getPos().getY(), getPos().getZ(), outputting ? 1 : 0)); } isDoingTransfer = outputting; } diff --git a/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java b/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java index b92c50fcb..22b9bc53d 100644 --- a/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java +++ b/src/main/java/vazkii/botania/common/core/proxy/CommonProxy.java @@ -90,6 +90,7 @@ import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.lib.LibMisc; import vazkii.botania.common.network.GuiHandler; +import vazkii.botania.common.network.PacketHandler; import vazkii.botania.common.world.SkyblockWorldEvents; import vazkii.botania.common.world.WorldTypeSkyblock; @@ -102,6 +103,7 @@ public class CommonProxy { ConfigHandler.loadConfig(event.getSuggestedConfigurationFile()); + PacketHandler.init(); ModSounds.init(); ModBlocks.init(); ModItems.init(); diff --git a/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java b/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java index a34f5e296..6017c5553 100644 --- a/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java +++ b/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java @@ -2,10 +2,16 @@ package vazkii.botania.common.network; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import vazkii.botania.client.core.handler.LightningHandler; +import vazkii.botania.common.Botania; +import vazkii.botania.common.core.handler.ConfigHandler; +import vazkii.botania.common.core.helper.Vector3; public class PacketBotaniaEffect implements IMessage { @@ -15,7 +21,6 @@ public class PacketBotaniaEffect implements IMessage { private double z; private int[] args; - public PacketBotaniaEffect() {} public PacketBotaniaEffect(EffectType type, double x, double y, double z, int... args) { @@ -54,9 +59,31 @@ public class PacketBotaniaEffect implements IMessage { public static class Handler implements IMessageHandler { @Override - public IMessage onMessage(PacketBotaniaEffect message, MessageContext ctx) { + public IMessage onMessage(final PacketBotaniaEffect message, final MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { - + switch (message.type) { + case POOL_CRAFT: { + for(int i = 0; i < 25; i++) { + float red = (float) Math.random(); + float green = (float) Math.random(); + float blue = (float) Math.random(); + Botania.proxy.sparkleFX(Minecraft.getMinecraft().theWorld, message.x + 0.5 + Math.random() * 0.4 - 0.2, message.y + 1, message.z + 0.5 + Math.random() * 0.4 - 0.2, + red, green, blue, (float) Math.random(), 10); + } + break; + } + case POOL_CHARGE: { + if(ConfigHandler.chargingAnimationEnabled) { + boolean outputting = message.args[0] == 1; + BlockPos pos = new BlockPos(message.x, message.y, message.z); + Vector3 itemVec = Vector3.fromBlockPos(pos).add(0.5, 0.5 + Math.random() * 0.3, 0.5); + Vector3 tileVec = Vector3.fromBlockPos(pos).add(0.2 + Math.random() * 0.6, 0, 0.2 + Math.random() * 0.6); + LightningHandler.spawnLightningBolt(Minecraft.getMinecraft().theWorld, outputting ? tileVec : itemVec, + outputting ? itemVec : tileVec, 80, Minecraft.getMinecraft().theWorld.rand.nextLong(), 0x4400799c, 0x4400C6FF); + } + break; + } + } }); return null; @@ -65,7 +92,8 @@ public class PacketBotaniaEffect implements IMessage { } public enum EffectType { - ; + POOL_CRAFT(0), + POOL_CHARGE(1); private final int argCount;