From 6cb1e063063ab3a40a56b411ac6046fdada73121 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Tue, 13 Jan 2015 21:02:11 -0500 Subject: [PATCH] New client -> server packet handler, added key to allow using the Project: Omega's signature effects --- .../AlchemicalWizardry.java | 10 +- .../BloodMagicConfiguration.java | 1 + .../alchemicalWizardry/ModBlocks.java | 4 + .../client/ClientEventHandler.java | 63 +++-- .../client/ClientProxy.java | 6 +- .../client/KeyBindings.java | 19 ++ .../common/AlchemicalWizardryEventHooks.java | 2 +- .../common/ClientToServerPacketHandler.java | 15 ++ .../common/MessageKeyPressed.java | 67 +++++ .../common/NewPacketHandler.java | 108 ++++++-- .../common/block/MimicBlock.java | 233 ++++++++++++++++++ .../common/items/armour/OmegaArmour.java | 8 + .../common/omega/OmegaParadigm.java | 11 + .../common/omega/OmegaParadigmWater.java | 49 ++++ .../common/potion/PotionAmphibian.java | 18 ++ .../common/rituals/RitualEffectOmegaTest.java | 6 +- .../common/tileEntity/TEMimicBlock.java | 217 ++++++++++++++++ 17 files changed, 800 insertions(+), 37 deletions(-) create mode 100644 src/main/java/WayofTime/alchemicalWizardry/client/KeyBindings.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/ClientToServerPacketHandler.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/MessageKeyPressed.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/block/MimicBlock.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/potion/PotionAmphibian.java create mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEMimicBlock.java diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 6c04a729..e0d1b2fb 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -63,6 +63,7 @@ import WayofTime.alchemicalWizardry.api.spell.SpellParadigmTool; import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistry; import WayofTime.alchemicalWizardry.common.AlchemicalWizardryEventHooks; import WayofTime.alchemicalWizardry.common.AlchemicalWizardryFuelHandler; +import WayofTime.alchemicalWizardry.common.ClientToServerPacketHandler; import WayofTime.alchemicalWizardry.common.CommonProxy; import WayofTime.alchemicalWizardry.common.LifeBucketHandler; import WayofTime.alchemicalWizardry.common.LifeEssence; @@ -116,6 +117,7 @@ import WayofTime.alchemicalWizardry.common.items.thaumcraft.ItemSanguineArmour; import WayofTime.alchemicalWizardry.common.omega.OmegaParadigmEarth; import WayofTime.alchemicalWizardry.common.omega.OmegaParadigmWater; import WayofTime.alchemicalWizardry.common.omega.OmegaRegistry; +import WayofTime.alchemicalWizardry.common.potion.PotionAmphibian; import WayofTime.alchemicalWizardry.common.potion.PotionBoost; import WayofTime.alchemicalWizardry.common.potion.PotionDeaf; import WayofTime.alchemicalWizardry.common.potion.PotionDemonCloak; @@ -247,6 +249,7 @@ import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar; import WayofTime.alchemicalWizardry.common.tileEntity.TEConduit; import WayofTime.alchemicalWizardry.common.tileEntity.TEHomHeart; import WayofTime.alchemicalWizardry.common.tileEntity.TEMasterStone; +import WayofTime.alchemicalWizardry.common.tileEntity.TEMimicBlock; import WayofTime.alchemicalWizardry.common.tileEntity.TEOrientable; import WayofTime.alchemicalWizardry.common.tileEntity.TEPedestal; import WayofTime.alchemicalWizardry.common.tileEntity.TEPlinth; @@ -313,6 +316,7 @@ public class AlchemicalWizardry public static Potion customPotionDeaf; public static Potion customPotionFeatherFall; public static Potion customPotionDemonCloak; + public static Potion customPotionAmphibian; public static int customPotionDrowningID; public static int customPotionBoostID; @@ -330,6 +334,7 @@ public class AlchemicalWizardry public static int customPotionDeafID; public static int customPotionFeatherFallID; public static int customPotionDemonCloakID; + public static int customPotionAmphibianID; public static boolean ritualDisabledWater; public static boolean ritualDisabledLava; @@ -534,6 +539,7 @@ public class AlchemicalWizardry FMLCommonHandler.instance().bus().register(eventHook); MinecraftForge.EVENT_BUS.register(eventHook); NewPacketHandler.INSTANCE.ordinal(); + ClientToServerPacketHandler.init(); } @EventHandler @@ -716,7 +722,8 @@ public class AlchemicalWizardry customPotionSoulHarden = (new PotionSoulHarden(customPotionSoulHardenID, false, 0).setIconIndex(0, 0).setPotionName("Soul Harden")); customPotionDeaf = (new PotionDeaf(customPotionDeafID, true, 0).setIconIndex(0, 0).setPotionName("Deafness")); customPotionFeatherFall = (new PotionFeatherFall(customPotionFeatherFallID, false, 0).setIconIndex(0, 0).setPotionName("Feather Fall")); - customPotionDemonCloak = (new PotionDemonCloak(customPotionDemonCloakID, false, 0).setIconIndex(0, 0).setPotionName("Demo Cloaking")); + customPotionDemonCloak = (new PotionDemonCloak(customPotionDemonCloakID, false, 0).setIconIndex(0, 0).setPotionName("Demon Cloaking")); + customPotionAmphibian = (new PotionAmphibian(customPotionAmphibianID, false, 0).setIconIndex(0, 0).setPotionName("Amphibian")); ItemStack masterBloodOrbStack = new ItemStack(ModItems.masterBloodOrb); @@ -747,6 +754,7 @@ public class AlchemicalWizardry GameRegistry.registerTileEntity(TEBellJar.class, "containerBellJar"); GameRegistry.registerTileEntity(TEAlchemicCalcinator.class, "containerAlchemicCalcinator"); GameRegistry.registerTileEntity(TEDemonChest.class, "containerDemonChest"); + GameRegistry.registerTileEntity(TEMimicBlock.class, "containerMimic"); ModBlocks.bloodRune.setHarvestLevel("pickaxe", 2); ModBlocks.speedRune.setHarvestLevel("pickaxe", 2); ModBlocks.efficiencyRune.setHarvestLevel("pickaxe", 2); diff --git a/src/main/java/WayofTime/alchemicalWizardry/BloodMagicConfiguration.java b/src/main/java/WayofTime/alchemicalWizardry/BloodMagicConfiguration.java index 7d5027f9..2ac09d08 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/BloodMagicConfiguration.java +++ b/src/main/java/WayofTime/alchemicalWizardry/BloodMagicConfiguration.java @@ -85,6 +85,7 @@ public class BloodMagicConfiguration AlchemicalWizardry.customPotionDeafID = config.get("Potion ID", "Deaf", 113).getInt(); AlchemicalWizardry.customPotionFeatherFallID = config.get("Potion ID", "FeatherFall", 114).getInt(); AlchemicalWizardry.customPotionDemonCloakID = config.get("Potion ID", "DemonCloak", 114).getInt(); + AlchemicalWizardry.customPotionAmphibianID = config.get("Potion ID", "Amphibian", 115).getInt(); MeteorParadigm.maxChance = config.get("meteor", "maxChance", 1000).getInt(); AlchemicalWizardry.doMeteorsDestroyBlocks = config.get("meteor", "doMeteorsDestroyBlocks", true).getBoolean(true); diff --git a/src/main/java/WayofTime/alchemicalWizardry/ModBlocks.java b/src/main/java/WayofTime/alchemicalWizardry/ModBlocks.java index 4932e815..e6ab7773 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/ModBlocks.java +++ b/src/main/java/WayofTime/alchemicalWizardry/ModBlocks.java @@ -30,6 +30,7 @@ import WayofTime.alchemicalWizardry.common.block.EmptySocket; import WayofTime.alchemicalWizardry.common.block.ImperfectRitualStone; import WayofTime.alchemicalWizardry.common.block.LargeBloodStoneBrick; import WayofTime.alchemicalWizardry.common.block.LifeEssenceBlock; +import WayofTime.alchemicalWizardry.common.block.MimicBlock; import WayofTime.alchemicalWizardry.common.block.RitualStone; import WayofTime.alchemicalWizardry.common.block.RuneOfSacrifice; import WayofTime.alchemicalWizardry.common.block.RuneOfSelfSacrifice; @@ -90,6 +91,7 @@ public class ModBlocks public static Block blockCrystalBelljar; public static Block blockDemonChest; public static Block blockCrystal; + public static Block blockMimic; public static void init() { @@ -127,6 +129,7 @@ public class ModBlocks blockCrystalBelljar = new BlockBelljar(); blockDemonChest = new BlockDemonChest(); blockCrystal = new BlockCrystal(); + blockMimic = new MimicBlock(); blockLifeEssence = new LifeEssenceBlock(); } @@ -171,6 +174,7 @@ public class ModBlocks GameRegistry.registerBlock(ModBlocks.blockCrystalBelljar, ItemBlockCrystalBelljar.class, "blockCrystalBelljar"); GameRegistry.registerBlock(ModBlocks.blockDemonChest, "blockDemonChest"); GameRegistry.registerBlock(ModBlocks.blockCrystal, ItemCrystalBlock.class, "blockCrystal"); + GameRegistry.registerBlock(ModBlocks.blockMimic, "blockMimic"); } public static void registerBlocksInInit() diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/ClientEventHandler.java b/src/main/java/WayofTime/alchemicalWizardry/client/ClientEventHandler.java index 7142278b..a3e0a531 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/ClientEventHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/ClientEventHandler.java @@ -1,22 +1,36 @@ package WayofTime.alchemicalWizardry.client; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.client.event.RenderBlockOverlayEvent; +import net.minecraftforge.client.event.sound.SoundEvent; import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.ModBlocks; import WayofTime.alchemicalWizardry.client.renderer.RenderHelper; +import WayofTime.alchemicalWizardry.common.ClientToServerPacketHandler; +import WayofTime.alchemicalWizardry.common.MessageKeyPressed; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.client.event.RenderPlayerEvent; -import net.minecraftforge.client.event.sound.SoundEvent; -import org.lwjgl.opengl.GL11; public class ClientEventHandler { private Minecraft mcClient = FMLClientHandler.instance().getClient(); + @SubscribeEvent + public void onKeyInput(InputEvent.KeyInputEvent event) + { + if(KeyBindings.omegaTest.isPressed()) + { + System.out.println("ping"); +// NewPacketHandler.INSTANCE.sendToServer(NewPacketHandler.getKeyboardPressPacket((byte)2)); + ClientToServerPacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(MessageKeyPressed.Key.OMEGA_ACTIVE)); + } + } + @SubscribeEvent public void onPlayerSoundEvent(SoundEvent event) { @@ -27,9 +41,26 @@ public class ClientEventHandler if (player != null && player.isPotionActive(AlchemicalWizardry.customPotionDeaf)) { event.setResult(Result.DENY); + if(event.isCancelable()) + event.setCanceled(true); } } } + + @SubscribeEvent + public void onOverlayEvent(RenderBlockOverlayEvent event) + { + if(event.overlayType == RenderBlockOverlayEvent.OverlayType.WATER && event.player.isPotionActive(AlchemicalWizardry.customPotionAmphibian.id))//TODO Placeholder for new potion effect + if(event.isCancelable()) + { + event.setCanceled(true); + } + + if(event.blockForOverlay == ModBlocks.blockMimic && event.isCancelable()) + { + event.setCanceled(true); + } + } @SubscribeEvent public void onTick(RenderTickEvent event) @@ -43,15 +74,15 @@ public class ClientEventHandler } } - @SubscribeEvent - public void onRenderLivingPlayerPre(RenderPlayerEvent.Pre event) - { - GL11.glDisable(2929); - } - - @SubscribeEvent - public void onRenderLivingPlayerPost(RenderPlayerEvent.Post event) - { - GL11.glEnable(2929); - } +// @SubscribeEvent +// public void onRenderLivingPlayerPre(RenderPlayerEvent.Pre event) +// { +// GL11.glDisable(2929); +// } +// +// @SubscribeEvent +// public void onRenderLivingPlayerPost(RenderPlayerEvent.Post event) +// { +// GL11.glEnable(2929); +// } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/ClientProxy.java b/src/main/java/WayofTime/alchemicalWizardry/client/ClientProxy.java index 02464f00..6b85b67a 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/client/ClientProxy.java +++ b/src/main/java/WayofTime/alchemicalWizardry/client/ClientProxy.java @@ -3,6 +3,7 @@ package WayofTime.alchemicalWizardry.client; import net.minecraft.item.ItemBlock; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.MinecraftForge; import WayofTime.alchemicalWizardry.ModBlocks; import WayofTime.alchemicalWizardry.api.spell.EntitySpellProjectile; import WayofTime.alchemicalWizardry.common.CommonProxy; @@ -178,6 +179,9 @@ public class ClientProxy extends CommonProxy @Override public void registerEvents() { - FMLCommonHandler.instance().bus().register(new ClientEventHandler()); + Object ob = new ClientEventHandler(); + FMLCommonHandler.instance().bus().register(ob); + MinecraftForge.EVENT_BUS.register(ob); + KeyBindings.init(); } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/client/KeyBindings.java b/src/main/java/WayofTime/alchemicalWizardry/client/KeyBindings.java new file mode 100644 index 00000000..26943f9b --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/client/KeyBindings.java @@ -0,0 +1,19 @@ +package WayofTime.alchemicalWizardry.client; + +import net.minecraft.client.settings.KeyBinding; + +import org.lwjgl.input.Keyboard; + +import cpw.mods.fml.client.registry.ClientRegistry; + +public class KeyBindings +{ + public static KeyBinding omegaTest; + + public static void init() + { + omegaTest = new KeyBinding("key.ping", Keyboard.KEY_O, "key.categories.alchemicalwizardry"); + + ClientRegistry.registerKeyBinding(omegaTest); + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java b/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java index c75502be..732241ab 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java @@ -440,7 +440,7 @@ public class AlchemicalWizardryEventHooks event.entityLiving.fallDistance = 0; } - if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionDrowning)) + if (event.entityLiving.isPotionActive(AlchemicalWizardry.customPotionDrowning) && ! event.entityLiving.isPotionActive(Potion.waterBreathing)) { int i = event.entityLiving.getActivePotionEffect(AlchemicalWizardry.customPotionDrowning).getAmplifier(); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/ClientToServerPacketHandler.java b/src/main/java/WayofTime/alchemicalWizardry/common/ClientToServerPacketHandler.java new file mode 100644 index 00000000..077bf2c4 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/ClientToServerPacketHandler.java @@ -0,0 +1,15 @@ +package WayofTime.alchemicalWizardry.common; + +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; + +public class ClientToServerPacketHandler +{ + public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("alchemicalwizardry"); + + public static void init() + { + INSTANCE.registerMessage(MessageKeyPressed.class, MessageKeyPressed.class, 0, Side.SERVER); + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/MessageKeyPressed.java b/src/main/java/WayofTime/alchemicalWizardry/common/MessageKeyPressed.java new file mode 100644 index 00000000..b1febbd0 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/MessageKeyPressed.java @@ -0,0 +1,67 @@ +package WayofTime.alchemicalWizardry.common; + +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + +public class MessageKeyPressed implements IMessage, IMessageHandler +{ + private byte keyPressed; + + public MessageKeyPressed() + { + } + + public MessageKeyPressed(Key key) + { + if (key == Key.OMEGA_ACTIVE) + { + this.keyPressed = (byte) Key.OMEGA_ACTIVE.ordinal(); + } + } + + @Override + public void fromBytes(ByteBuf buf) + { + this.keyPressed = buf.readByte(); + } + + @Override + public void toBytes(ByteBuf buf) + { + buf.writeByte(keyPressed); + } + + @Override + public IMessage onMessage(MessageKeyPressed message, MessageContext ctx) + { + EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity; + + if(message.keyPressed == Key.OMEGA_ACTIVE.ordinal()) + { + if(entityPlayer != null) + { + ItemStack[] armourInventory = entityPlayer.inventory.armorInventory; + if(armourInventory[2] != null) + { + ItemStack chestStack = armourInventory[2]; + if(chestStack.getItem() instanceof OmegaArmour) + { + ((OmegaArmour)chestStack.getItem()).onOmegaKeyPressed(entityPlayer, chestStack); + } + } + } + } + + return null; + } + + public static enum Key + { + OMEGA_ACTIVE; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java b/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java index 64487e5b..2b3b52ca 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java @@ -1,6 +1,7 @@ package WayofTime.alchemicalWizardry.common; import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -46,15 +47,8 @@ public enum NewPacketHandler { INSTANCE; - /** - * Our channel "pair" from {@link NetworkRegistry} - */ private EnumMap channels; - - /** - * Make our packet handler, and add an {@link IronChestCodec} always - */ private NewPacketHandler() { // request a channel pair for IronChest from the network registry @@ -64,6 +58,11 @@ public enum NewPacketHandler { addClientHandler(); } + if(FMLCommonHandler.instance().getSide() == Side.SERVER) + { + System.out.println("Server sided~"); + addServerHandler(); + } } @SideOnly(Side.CLIENT) @@ -87,15 +86,16 @@ public enum NewPacketHandler clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentReagentBarMessageHandler", new CurrentReagentBarMessageHandler()); clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentAddedHPMessageHandler", new CurrentAddedHPMessageHandler()); } + + @SideOnly(Side.SERVER) + private void addServerHandler() + { + FMLEmbeddedChannel serverChannel = this.channels.get(Side.SERVER); + String messageCodec = serverChannel.findChannelHandlerNameForType(TEAltarCodec.class); + serverChannel.pipeline().addAfter(messageCodec, "KeyboardMessageHandler", new KeyboardMessageHandler()); + } - /** - * This class simply handles the {@link IronChestMessage} when it's received - * at the client side It can contain client only code, because it's only run - * on the client. - * - * @author cpw - */ private static class TEAltarMessageHandler extends SimpleChannelInboundHandler { @Override @@ -305,6 +305,20 @@ public enum NewPacketHandler APISpellHelper.setCurrentAdditionalMaxHP(player, msg.maxHP); } } + + private static class KeyboardMessageHandler extends SimpleChannelInboundHandler + { + public KeyboardMessageHandler() + { + System.out.println("I am being created"); + } + @Override + protected void channelRead0(ChannelHandlerContext ctx, KeyboardMessage msg) throws Exception + { + System.out.println("Hmmm"); + + } + } public static class BMMessage { @@ -434,6 +448,43 @@ public enum NewPacketHandler float currentHP; float maxHP; } + + public static class KeyboardMessage extends BMMessage + { + byte keyPressed; + } + + private class ClientToServerCodec extends FMLIndexedMessageToMessageCodec + { + public ClientToServerCodec() + { + } + + @Override + public void encodeInto(ChannelHandlerContext ctx, BMMessage msg, ByteBuf target) throws Exception + { + target.writeInt(msg.index); + + + switch(msg.index) + { + + } + } + + @Override + public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, BMMessage msg) + { + int index = source.readInt(); + + System.out.println("Packet is recieved and being decoded"); + + switch(index) + { + + } + } + } private class TEAltarCodec extends FMLIndexedMessageToMessageCodec { @@ -453,6 +504,7 @@ public enum NewPacketHandler addDiscriminator(11, CurrentLPMessage.class); addDiscriminator(12, CurrentReagentBarMessage.class); addDiscriminator(13, CurrentAddedHPMessage.class); + addDiscriminator(14, KeyboardMessage.class); } @Override @@ -678,6 +730,12 @@ public enum NewPacketHandler target.writeFloat(((CurrentAddedHPMessage) msg).maxHP); break; + + case 14: + System.out.println("Packet is being encoded"); + + target.writeByte(((KeyboardMessage)msg).keyPressed); + break; } } @@ -911,6 +969,11 @@ public enum NewPacketHandler ((CurrentAddedHPMessage) msg).maxHP = dat.readFloat(); break; + + case 14: + System.out.println("Packet recieved: being decoded"); + ((KeyboardMessage)msg).keyPressed = dat.readByte(); + break; } } } @@ -1086,6 +1149,17 @@ public enum NewPacketHandler return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg); } + + public static Packet getKeyboardPressPacket(byte bt) + { + KeyboardMessage msg = new KeyboardMessage(); + msg.index = 14; + msg.keyPressed = bt; + + System.out.println("Packet is being created"); + + return INSTANCE.channels.get(Side.CLIENT).generatePacketFrom(msg); + } public void sendTo(Packet message, EntityPlayerMP player) { @@ -1106,4 +1180,10 @@ public enum NewPacketHandler this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); this.channels.get(Side.SERVER).writeAndFlush(message); } + + public void sendToServer(Packet message) + { + this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); + this.channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/block/MimicBlock.java b/src/main/java/WayofTime/alchemicalWizardry/common/block/MimicBlock.java new file mode 100644 index 00000000..ba9d2907 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/block/MimicBlock.java @@ -0,0 +1,233 @@ +package WayofTime.alchemicalWizardry.common.block; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.particle.EffectRenderer; +import net.minecraft.client.particle.EntityDiggingFX; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.common.tileEntity.TEMimicBlock; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class MimicBlock extends BlockContainer +{ + public MimicBlock() + { + super(Material.water); + setHardness(2.0F); + setResistance(5.0F); + setCreativeTab(AlchemicalWizardry.tabBloodMagic); + this.setBlockName("blockMimic"); +// this.setBlockBounds(0, 0, 0, 0, 0, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) + { + TileEntity TE = world.getTileEntity(x, y, z); + if(!(TE instanceof TEMimicBlock)) + { + return true; + } + TEMimicBlock mimic = (TEMimicBlock)TE; + + Block block = mimic.getBlock(); + + return block != null ? block.shouldSideBeRendered(world, x, y, z, side) : true; + } + + @SideOnly(Side.CLIENT) + public int getRenderBlockPass() + { + return 1; + } + + @Override + public boolean canCollideCheck(int meta, boolean bool) + { + return meta == 1; + } + + @SideOnly(Side.CLIENT) + @Override + /** + * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side + */ + public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int side) + { + TileEntity TE = blockAccess.getTileEntity(x, y, z); + TEMimicBlock mimic = (TEMimicBlock)TE; + Block block = mimic.getBlock(); + int meta = mimic.getMetaOfMimic(); + + return block != null ? block.getIcon(side, meta) : this.blockIcon; + } + + public boolean isOpaqueCube() + { + return false; + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) + { + return new TEMimicBlock(); + } + + @Override + public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, int z, int metadata) + { + return false; + } + + @Override + public int quantityDropped(int meta, int fortune, Random random) + { + return 0; + } + + @Override + public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int meta) + { + TileEntity tile = world.getTileEntity(x, y, z); + if(tile instanceof TEMimicBlock) + { + Block block = ((TEMimicBlock) tile).getBlock(); + int mimicMeta = ((TEMimicBlock) tile).getMetaOfMimic(); + + if(block != null) + { + return block.isBlockSolid(world, x, y, z, mimicMeta); + } + } + return super.isBlockSolid(world, x, y, z, meta); + } + + @Override + public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer effectRenderer) + { + TileEntity tile = world.getTileEntity(target.blockX, target.blockY, target.blockZ); + + TEMimicBlock TE = (TEMimicBlock)tile; + + if (TE != null) + { + Block block = TE.getBlock(); + + double xOffset = target.blockX + world.rand.nextDouble() * (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX() - 0.1F * 2.0F) + 0.1F + block.getBlockBoundsMinX(); + double yOffset = target.blockY + world.rand.nextDouble() * (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY() - 0.1F * 2.0F) + 0.1F + block.getBlockBoundsMinY(); + double zOffset = target.blockZ + world.rand.nextDouble() * (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ() - 0.1F * 2.0F) + 0.1F + block.getBlockBoundsMinZ(); + + switch (target.sideHit) { + case 0: + yOffset = target.blockY + block.getBlockBoundsMinY() - 0.1D; + break; + case 1: + yOffset = target.blockY + block.getBlockBoundsMaxY() + 0.1D; + break; + case 2: + zOffset = target.blockZ + block.getBlockBoundsMinZ() - 0.1D; + break; + case 3: + zOffset = target.blockZ + block.getBlockBoundsMaxZ() + 0.1D; + break; + case 4: + xOffset = target.blockX + block.getBlockBoundsMinX() - 0.1D; + break; + case 5: + xOffset = target.blockX + block.getBlockBoundsMaxX() + 0.1D; + break; + } + + MimicBlock.addHitEffect(TE, target, xOffset, yOffset, zOffset, null, effectRenderer); + + return true; + + } + + return super.addHitEffects(world, target, effectRenderer); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { + TEMimicBlock tile = (TEMimicBlock)world.getTileEntity(x, y, z); + Block block = tile.getBlock(); + + return block != null ? block.getCollisionBoundingBoxFromPool(world, x, y, z) : super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess blockAccess, int x, int y, int z) + { + TEMimicBlock TE = (TEMimicBlock)blockAccess.getTileEntity(x, y, z); + if (TE != null) + { + Block block = TE.getBlock(); + if(block != null) + { + return block.colorMultiplier(blockAccess, x, y, z); + } + } + + return super.colorMultiplier(blockAccess, x, y, z); + } + + @Override + public void velocityToAddToEntity(World world, int x, int y, int z, Entity entity, Vec3 vec) + { + TEMimicBlock TE = (TEMimicBlock)world.getTileEntity(x, y, z); + if (TE != null) + { + Block block = TE.getBlock(); + if(block != null) + { + block.velocityToAddToEntity(world, x, y, z, entity, vec); + } + } + } + + public static void addHitEffect(TEMimicBlock TE, MovingObjectPosition target, double x, double y, double z, ItemStack itemStack, EffectRenderer effectRenderer) + { + EntityDiggingFX particle = new EntityDiggingFX(TE.getWorldObj(), x, y, z, 0.0D, 0.0D, 0.0D, TE.getBlock(), TE.getMetaOfMimic()); + effectRenderer.addEffect(particle.applyColourMultiplier(target.blockX, target.blockY, target.blockZ).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F)); + } + + @Override + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) + { + TEMimicBlock TE = (TEMimicBlock)world.getTileEntity(x, y, z); + if (TE != null) + { + if(TE.getBlockEffectWhileInside(entity, x, y, z)) + { + return; + }else + { + Block block = TE.getBlock(); + if(block != null) + { + block.onEntityCollidedWithBlock(world, x, y, z, entity); + return; + } + } + } + + super.onEntityCollidedWithBlock(world, x, y, z, entity); + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/armour/OmegaArmour.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/armour/OmegaArmour.java index 12e2d0ec..23547d38 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/armour/OmegaArmour.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/armour/OmegaArmour.java @@ -172,4 +172,12 @@ public abstract class OmegaArmour extends BoundArmour return super.getArmorModel(entityLiving, itemStack, armorSlot); } } + + public void onOmegaKeyPressed(EntityPlayer player, ItemStack stack) + { + if(paradigm != null) + { + paradigm.onOmegaKeyPressed(player, stack); + } + } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigm.java b/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigm.java index b2680bff..4033caa6 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigm.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigm.java @@ -1,5 +1,6 @@ package WayofTime.alchemicalWizardry.common.omega; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -89,4 +90,14 @@ public class OmegaParadigm { } + + public void onOmegaKeyPressed(EntityPlayer player, ItemStack stack) + { + + } + + public boolean getBlockEffectWhileInside(Entity entity, int x, int y, int z) + { + return false; + } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigmWater.java b/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigmWater.java index f4324349..06a7e2e9 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigmWater.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/omega/OmegaParadigmWater.java @@ -1,8 +1,17 @@ package WayofTime.alchemicalWizardry.common.omega; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour; +import WayofTime.alchemicalWizardry.common.tileEntity.TEMimicBlock; public class OmegaParadigmWater extends OmegaParadigm { @@ -22,4 +31,44 @@ public class OmegaParadigmWater extends OmegaParadigm return 1; } } + + @Override + public void onUpdate(World world, EntityPlayer player, ItemStack stack) + { + player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 3, 0, true)); + player.addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionAmphibian.id, 3, 0, true)); + } + + @Override + public boolean getBlockEffectWhileInside(Entity entity, int x, int y, int z) + { + if(entity instanceof EntityLivingBase) + { + ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionDrowning.id, 100, 1)); + } + return true; + } + + @Override + public void onOmegaKeyPressed(EntityPlayer player, ItemStack stack) + { + World world = player.worldObj; + + int x = (int) Math.round(player.posX); + int y = (int) Math.round(player.posY); + int z = (int) Math.round(player.posZ); + + int range = 3; + + for(int i=-range; i<=range; i++) + { + for(int j=-range; j<=range; j++) + { + for(int k=-range; k<=range; k++) + { + TEMimicBlock.createMimicBlockAtLocation(world, x+i, y+j, z+k, 300, Blocks.water, 0, ReagentRegistry.aquasalusReagent); + } + } + } + } } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/potion/PotionAmphibian.java b/src/main/java/WayofTime/alchemicalWizardry/common/potion/PotionAmphibian.java new file mode 100644 index 00000000..1e3afb29 --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/potion/PotionAmphibian.java @@ -0,0 +1,18 @@ +package WayofTime.alchemicalWizardry.common.potion; + +import net.minecraft.potion.Potion; + +public class PotionAmphibian extends Potion +{ + public PotionAmphibian(int par1, boolean par2, int par3) + { + super(par1, par2, par3); + } + + @Override + public Potion setIconIndex(int par1, int par2) + { + super.setIconIndex(par1, par2); + return this; + } +} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/rituals/RitualEffectOmegaTest.java b/src/main/java/WayofTime/alchemicalWizardry/common/rituals/RitualEffectOmegaTest.java index 7a8e898c..973b7199 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/rituals/RitualEffectOmegaTest.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/rituals/RitualEffectOmegaTest.java @@ -42,10 +42,8 @@ public class RitualEffectOmegaTest extends RitualEffect List playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, range, range); for(EntityPlayer player : playerList) - { -// OmegaParadigm waterParadigm = new OmegaParadigm(ReagentRegistry.aquasalusReagent, ModItems.boundHelmetWater, ModItems.boundPlateWater, ModItems.boundLeggingsWater, ModItems.boundBootsWater, new ReagentRegenConfiguration(1, 1, 1)); - - Reagent reagent = ReagentRegistry.terraeReagent; + { + Reagent reagent = ReagentRegistry.aquasalusReagent; OmegaParadigm waterParadigm = OmegaRegistry.getParadigmForReagent(reagent); waterParadigm.convertPlayerArmour(player); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEMimicBlock.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEMimicBlock.java new file mode 100644 index 00000000..15f8ea1b --- /dev/null +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEMimicBlock.java @@ -0,0 +1,217 @@ +package WayofTime.alchemicalWizardry.common.tileEntity; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants; +import WayofTime.alchemicalWizardry.ModBlocks; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; +import WayofTime.alchemicalWizardry.common.omega.OmegaParadigm; +import WayofTime.alchemicalWizardry.common.omega.OmegaRegistry; + +public class TEMimicBlock extends TileEntity +{ + private ItemStack[] inv; + public Reagent reagent; + + private int ticksRemaining; + + public TEMimicBlock() + { + this.inv = new ItemStack[1]; + + ticksRemaining = 0; + } + + @Override + public Packet getDescriptionPacket() + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -999, nbttagcompound); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) + { + super.onDataPacket(net, packet); + readFromNBT(packet.func_148857_g()); + } + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + super.readFromNBT(par1NBTTagCompound); + NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i); + int slot = tag.getByte("Slot"); + + if (slot >= 0 && slot < inv.length) + { + inv[slot] = ItemStack.loadItemStackFromNBT(tag); + } + } + + ticksRemaining = par1NBTTagCompound.getInteger("ticksRemaining"); + reagent = ReagentRegistry.getReagentForKey(par1NBTTagCompound.getString("reagent")); + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeToNBT(par1NBTTagCompound); + NBTTagList itemList = new NBTTagList(); + + for (int i = 0; i < inv.length; i++) + { + ItemStack stack = inv[i]; + + if (inv[i] != null) + { + NBTTagCompound tag = new NBTTagCompound(); + tag.setByte("Slot", (byte) i); + inv[i].writeToNBT(tag); + itemList.appendTag(tag); + } + } + + par1NBTTagCompound.setTag("Inventory", itemList); + par1NBTTagCompound.setInteger("ticksRemaining", ticksRemaining); + par1NBTTagCompound.setString("reagent", ReagentRegistry.getKeyForReagent(reagent)); + } + + @Override + public void updateEntity() + { + super.updateEntity(); + + this.ticksRemaining--; + + if (this.ticksRemaining <= 0) + { + this.returnContainedBlock(); + } + } + + public static boolean createMimicBlockAtLocation(World world, int x, int y, int z, int duration, Block block, int meta, Reagent reagent) + { + if (block == null) + { + return false; + } + + if (world.getTileEntity(x, y, z) == null && world.isAirBlock(x, y, z)) + { + ItemStack item = new ItemStack(block, 1, meta); + + world.setBlock(x, y, z, ModBlocks.blockMimic); + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TEMimicBlock) + { + ((TEMimicBlock) tile).setContainedItem(item); + ((TEMimicBlock) tile).setDuration(duration); + ((TEMimicBlock) tile).reagent = reagent; + world.markBlockForUpdate(x, y, z); + return true; + } + } + + return false; + } + + public static boolean createMimicBlockAtLocation(World world, int x, int y, int z, int duration, Block block, int meta) + { + return createMimicBlockAtLocation(world, x, y, z, duration, block, meta); + } + + public void setDuration(int dur) + { + this.ticksRemaining = dur; + } + + public void resetDuration(int dur) + { + if (this.ticksRemaining < dur) + { + this.ticksRemaining = dur; + } + } + + public void setContainedItem(ItemStack item) + { + this.inv[0] = item; + } + + public void returnContainedBlock() + { +// ItemStack item = this.inv[0]; +// if (item != null) +// { +// if (item.getItem() instanceof ItemBlock) +// { +// Block block = ((ItemBlock) item.getItem()).field_150939_a; +// int meta = item.getItemDamage(); +// +// if (block != null) +// { +// this.worldObj.setBlock(xCoord, yCoord, zCoord, block, meta, 6); +// } +// } +// +// } else + { + this.worldObj.setBlockToAir(xCoord, yCoord, zCoord); + } + } + + public Block getBlock() + { + ItemStack item = this.inv[0]; + if(item != null) + { + if (item.getItem() instanceof ItemBlock) + { + Block block = ((ItemBlock) item.getItem()).field_150939_a; + return block; + } + } + return null; + } + + public int getMetaOfMimic() + { + ItemStack item = this.inv[0]; + if(item != null) + { + return item.getItemDamage(); + } + + return 0; + } + + public boolean getBlockEffectWhileInside(Entity entity, int x, int y, int z) + { + if(reagent != null) + { + OmegaParadigm paradigm = OmegaRegistry.getParadigmForReagent(reagent); + if(paradigm != null) + { + return paradigm.getBlockEffectWhileInside(entity, x, y, z); + } + } + + return false; + } +}