From ec0e6be9e153ab2a92930f3fd8a1f8f4074542a8 Mon Sep 17 00:00:00 2001 From: Jared Date: Sun, 11 Mar 2018 19:54:45 +0200 Subject: [PATCH 1/2] Removed reliance on ARL Closes #22 --- build.properties | 8 +- .../reskillable/base/CommonProxy.java | 4 +- .../reskillable/base/LevelLockHandler.java | 6 +- .../reskillable/base/PlayerData.java | 6 +- .../reskillable/client/base/HUDHandler.java | 3 +- .../reskillable/client/base/RenderHelper.java | 125 ++++++++++++++++++ .../reskillable/client/gui/GuiSkillInfo.java | 17 +-- .../reskillable/client/gui/GuiSkills.java | 3 +- .../gui/handler/InventoryTabHandler.java | 2 +- .../reskillable/lib/LibMisc.java | 2 +- .../reskillable/network/MessageDataSync.java | 48 ++++--- .../reskillable/network/MessageDodge.java | 30 ++++- .../reskillable/network/MessageLevelUp.java | 60 +++++---- .../network/MessageLockedItem.java | 47 ++++--- .../reskillable/network/MessageRegister.java | 16 --- .../network/MessageUnlockUnlockable.java | 54 +++++--- .../reskillable/network/PacketHandler.java | 20 +++ 17 files changed, 325 insertions(+), 126 deletions(-) create mode 100644 src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java delete mode 100644 src/main/java/codersafterdark/reskillable/network/MessageRegister.java create mode 100644 src/main/java/codersafterdark/reskillable/network/PacketHandler.java diff --git a/build.properties b/build.properties index 867a7d0b..02863596 100644 --- a/build.properties +++ b/build.properties @@ -1,10 +1,10 @@ # -#Sat Mar 10 15:19:18 CET 2018 +#Sun Mar 11 19:14:41 CAT 2018 version=beta mc_mappings=snapshot_20170624 dir_output=../Build Output/Reskillable/ -dir_repo=./ -forge_version=14.23.2.2624 mc_version=1.12.2 -build_number=39 +forge_version=14.23.2.2624 +dir_repo=./ +build_number=40 mod_name=Reskillable diff --git a/src/main/java/codersafterdark/reskillable/base/CommonProxy.java b/src/main/java/codersafterdark/reskillable/base/CommonProxy.java index 8ec3aaa0..18abdf64 100644 --- a/src/main/java/codersafterdark/reskillable/base/CommonProxy.java +++ b/src/main/java/codersafterdark/reskillable/base/CommonProxy.java @@ -1,7 +1,7 @@ package codersafterdark.reskillable.base; import codersafterdark.reskillable.event.RegisterUnlockablesEvent; -import codersafterdark.reskillable.network.MessageRegister; +import codersafterdark.reskillable.network.PacketHandler; import codersafterdark.reskillable.skill.Skills; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.MinecraftForge; @@ -18,7 +18,7 @@ public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(PlayerDataHandler.EventHandler.class); MinecraftForge.EVENT_BUS.register(LevelLockHandler.class); ConfigHandler.init(event.getSuggestedConfigurationFile()); - MessageRegister.init(); + PacketHandler.preInit(); } public void init(FMLInitializationEvent event) { diff --git a/src/main/java/codersafterdark/reskillable/base/LevelLockHandler.java b/src/main/java/codersafterdark/reskillable/base/LevelLockHandler.java index afa24c95..c7650499 100644 --- a/src/main/java/codersafterdark/reskillable/base/LevelLockHandler.java +++ b/src/main/java/codersafterdark/reskillable/base/LevelLockHandler.java @@ -1,6 +1,7 @@ package codersafterdark.reskillable.base; -import codersafterdark.reskillable.network.MessageLockedItem; +import codersafterdark.reskillable.network.*; +import mcp.mobius.waila.handlers.NetworkHandler; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -19,7 +20,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import net.minecraftforge.fml.relauncher.*; -import vazkii.arl.network.NetworkHandler; import java.util.*; @@ -245,7 +245,7 @@ private static void enforce(PlayerInteractEvent event) { public static void tellPlayer(EntityPlayer player, ItemStack stack, String msg) { if(player instanceof EntityPlayerMP) { MessageLockedItem message = new MessageLockedItem(stack, msg); - NetworkHandler.INSTANCE.sendTo(message, (EntityPlayerMP) player); + PacketHandler.INSTANCE.sendTo(message, (EntityPlayerMP) player); } } diff --git a/src/main/java/codersafterdark/reskillable/base/PlayerData.java b/src/main/java/codersafterdark/reskillable/base/PlayerData.java index 9455ad9a..01760710 100644 --- a/src/main/java/codersafterdark/reskillable/base/PlayerData.java +++ b/src/main/java/codersafterdark/reskillable/base/PlayerData.java @@ -1,10 +1,11 @@ package codersafterdark.reskillable.base; -import codersafterdark.reskillable.network.MessageDataSync; +import codersafterdark.reskillable.network.*; import codersafterdark.reskillable.skill.Skill; import codersafterdark.reskillable.skill.Skills; import codersafterdark.reskillable.skill.base.Ability; import codersafterdark.reskillable.skill.base.IAbilityEventHandler; +import mcp.mobius.waila.handlers.NetworkHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementManager; import net.minecraft.advancements.AdvancementProgress; @@ -21,7 +22,6 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; -import vazkii.arl.network.NetworkHandler; import java.lang.ref.WeakReference; import java.util.HashMap; @@ -118,7 +118,7 @@ public void sync() { if (player != null && player instanceof EntityPlayerMP) { MessageDataSync message = new MessageDataSync(this); - NetworkHandler.INSTANCE.sendTo(message, (EntityPlayerMP) player); + PacketHandler.INSTANCE.sendTo(message, (EntityPlayerMP) player); } } } diff --git a/src/main/java/codersafterdark/reskillable/client/base/HUDHandler.java b/src/main/java/codersafterdark/reskillable/client/base/HUDHandler.java index 7e596c96..76b5578f 100644 --- a/src/main/java/codersafterdark/reskillable/client/base/HUDHandler.java +++ b/src/main/java/codersafterdark/reskillable/client/base/HUDHandler.java @@ -12,14 +12,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.*; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.translation.I18n; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import vazkii.arl.util.RenderHelper; public class HUDHandler { diff --git a/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java b/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java new file mode 100644 index 00000000..2912072f --- /dev/null +++ b/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java @@ -0,0 +1,125 @@ +package codersafterdark.reskillable.client.base; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.*; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; + +import java.util.List; + +public class RenderHelper { + + public static void renderTooltip(int x, int y, List tooltipData) { + int color = 0x505000ff; + int color2 = 0xf0100010; + + renderTooltip(x, y, tooltipData, color, color2); + } + + public static void renderTooltip(int x, int y, List tooltipData, int color, int color2) { + boolean lighting = GL11.glGetBoolean(GL11.GL_LIGHTING); + if(lighting) + net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting(); + + if(!tooltipData.isEmpty()) { + int var5 = 0; + int var6; + int var7; + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + for(var6 = 0; var6 < tooltipData.size(); ++var6) { + var7 = fontRenderer.getStringWidth(tooltipData.get(var6)); + if(var7 > var5) + var5 = var7; + } + var6 = x + 12; + var7 = y - 12; + int var9 = 8; + if(tooltipData.size() > 1) + var9 += 2 + (tooltipData.size() - 1) * 10; + + ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft()); + int right = var6 + var5 + 5; + int swidth = res.getScaledWidth(); + if(right > swidth) { + int diff = right - swidth; + var6 -= diff; + } + + int bottom = var7 + var9 + 5; + int sheight = res.getScaledHeight(); + if(bottom > sheight) { + int diff = bottom - sheight; + var7 -= diff; + } + + float z = 300F; + drawGradientRect(var6 - 3, var7 - 4, z, var6 + var5 + 3, var7 - 3, color2, color2); + drawGradientRect(var6 - 3, var7 + var9 + 3, z, var6 + var5 + 3, var7 + var9 + 4, color2, color2); + drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 + var9 + 3, color2, color2); + drawGradientRect(var6 - 4, var7 - 3, z, var6 - 3, var7 + var9 + 3, color2, color2); + drawGradientRect(var6 + var5 + 3, var7 - 3, z, var6 + var5 + 4, var7 + var9 + 3, color2, color2); + int var12 = (color & 0xFFFFFF) >> 1 | color & -16777216; + drawGradientRect(var6 - 3, var7 - 3 + 1, z, var6 - 3 + 1, var7 + var9 + 3 - 1, color, var12); + drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, z, var6 + var5 + 3, var7 + var9 + 3 - 1, color, var12); + drawGradientRect(var6 - 3, var7 - 3, z, var6 + var5 + 3, var7 - 3 + 1, color, color); + drawGradientRect(var6 - 3, var7 + var9 + 2, z, var6 + var5 + 3, var7 + var9 + 3, var12, var12); + + GlStateManager.disableDepth(); + for(int var13 = 0; var13 < tooltipData.size(); ++var13) { + String var14 = tooltipData.get(var13); + fontRenderer.drawStringWithShadow(var14, var6, var7, -1); + if(var13 == 0) + var7 += 2; + var7 += 10; + } + GlStateManager.enableDepth(); + } + if(!lighting) + net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting(); + GlStateManager.color(1F, 1F, 1F, 1F); + } + + public static void drawGradientRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) { + float var7 = (par5 >> 24 & 255) / 255F; + float var8 = (par5 >> 16 & 255) / 255F; + float var9 = (par5 >> 8 & 255) / 255F; + float var10 = (par5 & 255) / 255F; + float var11 = (par6 >> 24 & 255) / 255F; + float var12 = (par6 >> 16 & 255) / 255F; + float var13 = (par6 >> 8 & 255) / 255F; + float var14 = (par6 & 255) / 255F; + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + Tessellator var15 = Tessellator.getInstance(); + BufferBuilder buff = var15.getBuffer(); + buff.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + buff.pos(par3, par2, z).color(var8, var9, var10, var7).endVertex(); + buff.pos(par1, par2, z).color(var8, var9, var10, var7).endVertex(); + buff.pos(par1, par4, z).color(var12, var13, var14, var11).endVertex(); + buff.pos(par3, par4, z).color(var12, var13, var14, var11).endVertex(); + var15.draw(); + GlStateManager.shadeModel(GL11.GL_FLAT); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + + public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) { + drawTexturedModalRect(par1, par2, z, par3, par4, par5, par6, 0.00390625F, 0.00390625F); + } + + public static void drawTexturedModalRect(int par1, int par2, float z, int par3, int par4, int par5, int par6, float f, float f1) { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buff = tessellator.getBuffer(); + buff.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + buff.pos(par1 + 0, par2 + par6, z).tex((par3 + 0) * f, (par4 + par6) * f1).endVertex(); + buff.pos(par1 + par5, par2 + par6, z).tex((par3 + par5) * f, (par4 + par6) * f1).endVertex(); + buff.pos(par1 + par5, par2 + 0, z).tex((par3 + par5) * f, (par4 + 0) * f1).endVertex(); + buff.pos(par1 + 0, par2 + 0, z).tex((par3 + 0) * f, (par4 + 0) * f1).endVertex(); + tessellator.draw(); + } +} diff --git a/src/main/java/codersafterdark/reskillable/client/gui/GuiSkillInfo.java b/src/main/java/codersafterdark/reskillable/client/gui/GuiSkillInfo.java index b27735bb..2914d276 100644 --- a/src/main/java/codersafterdark/reskillable/client/gui/GuiSkillInfo.java +++ b/src/main/java/codersafterdark/reskillable/client/gui/GuiSkillInfo.java @@ -1,14 +1,12 @@ package codersafterdark.reskillable.client.gui; -import codersafterdark.reskillable.base.ConfigHandler; import codersafterdark.reskillable.base.PlayerData; import codersafterdark.reskillable.base.PlayerDataHandler; import codersafterdark.reskillable.base.PlayerSkillInfo; import codersafterdark.reskillable.client.gui.button.GuiButtonLevelUp; import codersafterdark.reskillable.client.gui.handler.InventoryTabHandler; import codersafterdark.reskillable.lib.LibMisc; -import codersafterdark.reskillable.network.MessageLevelUp; -import codersafterdark.reskillable.network.MessageUnlockUnlockable; +import codersafterdark.reskillable.network.*; import codersafterdark.reskillable.skill.Skill; import codersafterdark.reskillable.skill.base.Unlockable; import net.minecraft.block.Block; @@ -17,20 +15,19 @@ import net.minecraft.client.gui.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.init.SoundEvents; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.translation.I18n; import org.lwjgl.opengl.GL11; -import vazkii.arl.network.NetworkHandler; -import vazkii.arl.util.RenderHelper; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static codersafterdark.reskillable.client.base.RenderHelper.renderTooltip; + public class GuiSkillInfo extends GuiScreen { public static final ResourceLocation SKILL_INFO_RES = new ResourceLocation(LibMisc.MOD_ID, "textures/gui/skill_info.png"); @@ -173,8 +170,8 @@ private void makeUnlockableTooltip(PlayerData data, PlayerSkillInfo info, int mo hoveredUnlockable.getRequirements().addRequirementsToTooltip(data, tooltip); else tooltip.add(TextFormatting.GREEN + I18n.translateToLocal("skillable.misc.unlocked")); tooltip.add(TextFormatting.GRAY + String.format(I18n.translateToLocal("skillable.misc.skillPoints"), hoveredUnlockable.cost)); - - RenderHelper.renderTooltip(mouseX, mouseY, tooltip); + + renderTooltip(mouseX, mouseY, tooltip); } private void addLongStringToTooltip(List tooltip, String longStr, int maxLen) { @@ -197,7 +194,7 @@ private void addLongStringToTooltip(List tooltip, String longStr, int ma protected void actionPerformed(GuiButton button) throws IOException { if (button == levelUpButton) { MessageLevelUp message = new MessageLevelUp(skill.getKey()); - NetworkHandler.INSTANCE.sendToServer(message); + PacketHandler.INSTANCE.sendToServer(message); } } @@ -208,7 +205,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx if (mouseButton == 0 && hoveredUnlockable != null && canPurchase) { mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F)); MessageUnlockUnlockable message = new MessageUnlockUnlockable(skill.getKey(), hoveredUnlockable.getKey()); - NetworkHandler.INSTANCE.sendToServer(message); + PacketHandler.INSTANCE.sendToServer(message); } else if (mouseButton == 1 || mouseButton == 3) mc.displayGuiScreen(new GuiSkills()); } diff --git a/src/main/java/codersafterdark/reskillable/client/gui/GuiSkills.java b/src/main/java/codersafterdark/reskillable/client/gui/GuiSkills.java index ff085fda..33400a6d 100644 --- a/src/main/java/codersafterdark/reskillable/client/gui/GuiSkills.java +++ b/src/main/java/codersafterdark/reskillable/client/gui/GuiSkills.java @@ -1,9 +1,9 @@ package codersafterdark.reskillable.client.gui; -import codersafterdark.reskillable.base.ConfigHandler; import codersafterdark.reskillable.base.PlayerData; import codersafterdark.reskillable.base.PlayerDataHandler; import codersafterdark.reskillable.base.PlayerSkillInfo; +import codersafterdark.reskillable.client.base.RenderHelper; import codersafterdark.reskillable.client.gui.handler.InventoryTabHandler; import codersafterdark.reskillable.lib.LibMisc; import codersafterdark.reskillable.skill.Skill; @@ -18,7 +18,6 @@ import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import vazkii.arl.util.RenderHelper; import java.io.IOException; import java.util.ArrayList; diff --git a/src/main/java/codersafterdark/reskillable/client/gui/handler/InventoryTabHandler.java b/src/main/java/codersafterdark/reskillable/client/gui/handler/InventoryTabHandler.java index ae497a63..41d90802 100644 --- a/src/main/java/codersafterdark/reskillable/client/gui/handler/InventoryTabHandler.java +++ b/src/main/java/codersafterdark/reskillable/client/gui/handler/InventoryTabHandler.java @@ -1,6 +1,7 @@ package codersafterdark.reskillable.client.gui.handler; import codersafterdark.reskillable.base.ConfigHandler; +import codersafterdark.reskillable.client.base.RenderHelper; import codersafterdark.reskillable.client.gui.GuiAbilities; import codersafterdark.reskillable.client.gui.GuiSkillInfo; import codersafterdark.reskillable.client.gui.GuiSkills; @@ -17,7 +18,6 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import scala.actors.threadpool.Arrays; -import vazkii.arl.util.RenderHelper; import java.util.List; diff --git a/src/main/java/codersafterdark/reskillable/lib/LibMisc.java b/src/main/java/codersafterdark/reskillable/lib/LibMisc.java index a73355ac..adfe3012 100644 --- a/src/main/java/codersafterdark/reskillable/lib/LibMisc.java +++ b/src/main/java/codersafterdark/reskillable/lib/LibMisc.java @@ -7,7 +7,7 @@ public final class LibMisc { public static final String MOD_NAME = "Reskillable"; public static final String BUILD = "GRADLE:BUILD"; public static final String VERSION = "GRADLE:VERSION-" + BUILD; - public static final String DEPENDENCIES = "required-before:autoreglib;"; + public static final String DEPENDENCIES = ""; // Proxy Constants public static final String PROXY_COMMON = "codersafterdark.reskillable.base.CommonProxy"; diff --git a/src/main/java/codersafterdark/reskillable/network/MessageDataSync.java b/src/main/java/codersafterdark/reskillable/network/MessageDataSync.java index d0ada9c6..5db819cd 100644 --- a/src/main/java/codersafterdark/reskillable/network/MessageDataSync.java +++ b/src/main/java/codersafterdark/reskillable/network/MessageDataSync.java @@ -1,37 +1,53 @@ package codersafterdark.reskillable.network; import codersafterdark.reskillable.Reskillable; -import codersafterdark.reskillable.base.PlayerData; -import codersafterdark.reskillable.base.PlayerDataHandler; +import codersafterdark.reskillable.base.*; import codersafterdark.reskillable.client.base.ClientTickHandler; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import vazkii.arl.network.NetworkMessage; - -public class MessageDataSync extends NetworkMessage { +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.*; +import net.minecraftforge.fml.relauncher.*; +public class MessageDataSync implements IMessage, IMessageHandler { + public NBTTagCompound cmp; - + public MessageDataSync() { } - + public MessageDataSync(PlayerData data) { cmp = new NBTTagCompound(); data.saveToNBT(cmp); } - + + @Override + public void fromBytes(ByteBuf buf) { + cmp = ByteBufUtils.readTag(buf); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeTag(buf, cmp); + } + + @Override + public IMessage onMessage(MessageDataSync message, MessageContext ctx) { + Minecraft.getMinecraft().addScheduledTask(() -> { + handleMessage(message); + }); + return null; + } + @SideOnly(Side.CLIENT) - public IMessage handleMessage(MessageContext context) { + public IMessage handleMessage(MessageDataSync message) { ClientTickHandler.scheduledActions.add(() -> { PlayerData data = PlayerDataHandler.get(Reskillable.proxy.getClientPlayer()); - data.loadFromNBT(cmp); + data.loadFromNBT(message.cmp); }); - + return null; } - } \ No newline at end of file diff --git a/src/main/java/codersafterdark/reskillable/network/MessageDodge.java b/src/main/java/codersafterdark/reskillable/network/MessageDodge.java index 840da4b5..3a8c986d 100644 --- a/src/main/java/codersafterdark/reskillable/network/MessageDodge.java +++ b/src/main/java/codersafterdark/reskillable/network/MessageDodge.java @@ -1,20 +1,36 @@ package codersafterdark.reskillable.network; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import vazkii.arl.network.NetworkMessage; - -public class MessageDodge extends NetworkMessage { +import net.minecraft.server.MinecraftServer; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.network.simpleimpl.*; +public class MessageDodge implements IMessage, IMessageHandler { + + @Override + public void fromBytes(ByteBuf buf) { + + } + + @Override + public void toBytes(ByteBuf buf) { + + } + @Override + public IMessage onMessage(MessageDodge message, MessageContext ctx) { + FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> handleMessage(ctx)); + return null; + } + public IMessage handleMessage(MessageContext context) { EntityPlayerMP player = context.getServerHandler().player; player.mcServer.addScheduledTask(() -> { player.addExhaustion(0.3F); }); - + return null; } - } diff --git a/src/main/java/codersafterdark/reskillable/network/MessageLevelUp.java b/src/main/java/codersafterdark/reskillable/network/MessageLevelUp.java index 175bb050..ed4405b4 100644 --- a/src/main/java/codersafterdark/reskillable/network/MessageLevelUp.java +++ b/src/main/java/codersafterdark/reskillable/network/MessageLevelUp.java @@ -1,43 +1,57 @@ package codersafterdark.reskillable.network; -import codersafterdark.reskillable.base.ConfigHandler; -import codersafterdark.reskillable.base.PlayerData; -import codersafterdark.reskillable.base.PlayerDataHandler; -import codersafterdark.reskillable.base.PlayerSkillInfo; -import codersafterdark.reskillable.skill.Skill; -import codersafterdark.reskillable.skill.Skills; +import codersafterdark.reskillable.base.*; +import codersafterdark.reskillable.skill.*; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import vazkii.arl.network.NetworkMessage; - -public class MessageLevelUp extends NetworkMessage { +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.*; +public class MessageLevelUp implements IMessage, IMessageHandler { + public String skill; - + public MessageLevelUp() { } - + public MessageLevelUp(String skill) { this.skill = skill; } - + + @Override + public void fromBytes(ByteBuf buf) { + skill = ByteBufUtils.readUTF8String(buf); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, skill); + } + @Override - public IMessage handleMessage(MessageContext context) { + public IMessage onMessage(MessageLevelUp message, MessageContext ctx) { + FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> handleMessage(message, ctx)); + return null; + } + + public IMessage handleMessage(MessageLevelUp message, MessageContext context) { EntityPlayer player = context.getServerHandler().player; - Skill skill = Skills.SKILLS.get(this.skill); + Skill skill = Skills.SKILLS.get(message.skill); PlayerData data = PlayerDataHandler.get(player); PlayerSkillInfo info = data.getSkillInfo(skill); - if (!info.isCapped()) { + if(!info.isCapped()) { int cost = info.getLevelUpCost(); - if (player.experienceLevel >= cost || player.isCreative()) { - if (!player.isCreative()) { - player.addExperienceLevel(-cost); - } - info.levelUp(); - data.saveAndSync(); + if(player.experienceLevel >= cost || player.isCreative()) { + if(!player.isCreative()) { + player.addExperienceLevel(-cost); } + info.levelUp(); + data.saveAndSync(); + } } return null; } + + } diff --git a/src/main/java/codersafterdark/reskillable/network/MessageLockedItem.java b/src/main/java/codersafterdark/reskillable/network/MessageLockedItem.java index fbf0bce3..c4cee455 100644 --- a/src/main/java/codersafterdark/reskillable/network/MessageLockedItem.java +++ b/src/main/java/codersafterdark/reskillable/network/MessageLockedItem.java @@ -1,40 +1,53 @@ package codersafterdark.reskillable.network; import codersafterdark.reskillable.client.base.HUDHandler; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import vazkii.arl.network.NetworkMessage; - -public class MessageLockedItem extends NetworkMessage { +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.*; +public class MessageLockedItem implements IMessage, IMessageHandler { + public static final String MSG_ITEM_LOCKED = "skillable.misc.itemLocked"; public static final String MSG_BLOCK_BREAK_LOCKED = "skillable.misc.blockBreakLocked"; public static final String MSG_BLOCK_USE_LOCKED = "skillable.misc.blockUseLocked"; public static final String MSG_ARMOR_EQUIP_LOCKED = "skillable.misc.armorEquipLocked"; - + public ItemStack stack; public String msg; - + public MessageLockedItem() { } - + public MessageLockedItem(ItemStack stack, String msg) { this.stack = stack; this.msg = msg; } - + + @Override - @SideOnly(Side.CLIENT) - public IMessage handleMessage(MessageContext context) { - HUDHandler.setLockMessage(stack, msg); - return null; + public void fromBytes(ByteBuf buf) { + stack = ByteBufUtils.readItemStack(buf); + msg = ByteBufUtils.readUTF8String(buf); } - + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeItemStack(buf, stack); + ByteBufUtils.writeUTF8String(buf, msg); + } + @Override - public IMessage onMessage(IMessage message, MessageContext ctx) { + public IMessage onMessage(MessageLockedItem message, MessageContext ctx) { + Minecraft.getMinecraft().addScheduledTask(() -> { + handleMessage(message, ctx); + }); + return null; + } + + public IMessage handleMessage(MessageLockedItem message, MessageContext ctx) { + HUDHandler.setLockMessage(message.stack, message.msg); return null; } } diff --git a/src/main/java/codersafterdark/reskillable/network/MessageRegister.java b/src/main/java/codersafterdark/reskillable/network/MessageRegister.java deleted file mode 100644 index 9057db68..00000000 --- a/src/main/java/codersafterdark/reskillable/network/MessageRegister.java +++ /dev/null @@ -1,16 +0,0 @@ -package codersafterdark.reskillable.network; - -import net.minecraftforge.fml.relauncher.Side; -import vazkii.arl.network.NetworkHandler; - -public class MessageRegister { - - public static void init() { - NetworkHandler.register(MessageDataSync.class, Side.CLIENT); - NetworkHandler.register(MessageLevelUp.class, Side.SERVER); - NetworkHandler.register(MessageUnlockUnlockable.class, Side.SERVER); - NetworkHandler.register(MessageLockedItem.class, Side.CLIENT); - NetworkHandler.register(MessageDodge.class, Side.SERVER); - } - -} diff --git a/src/main/java/codersafterdark/reskillable/network/MessageUnlockUnlockable.java b/src/main/java/codersafterdark/reskillable/network/MessageUnlockUnlockable.java index 991816dd..72999ff1 100644 --- a/src/main/java/codersafterdark/reskillable/network/MessageUnlockUnlockable.java +++ b/src/main/java/codersafterdark/reskillable/network/MessageUnlockUnlockable.java @@ -1,41 +1,57 @@ package codersafterdark.reskillable.network; -import codersafterdark.reskillable.base.PlayerData; -import codersafterdark.reskillable.base.PlayerDataHandler; -import codersafterdark.reskillable.base.PlayerSkillInfo; -import codersafterdark.reskillable.skill.Skill; -import codersafterdark.reskillable.skill.Skills; +import codersafterdark.reskillable.base.*; +import codersafterdark.reskillable.skill.*; import codersafterdark.reskillable.skill.base.Unlockable; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import vazkii.arl.network.NetworkMessage; - -public class MessageUnlockUnlockable extends NetworkMessage { +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.*; +public class MessageUnlockUnlockable implements IMessage, IMessageHandler { + public String skill, unlockable; - + public MessageUnlockUnlockable() { } - + public MessageUnlockUnlockable(String skill, String unlockable) { this.skill = skill; this.unlockable = unlockable; } - + + @Override + public void fromBytes(ByteBuf buf) { + skill = ByteBufUtils.readUTF8String(buf); + unlockable = ByteBufUtils.readUTF8String(buf); + } + @Override - public IMessage handleMessage(MessageContext context) { + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, skill); + ByteBufUtils.writeUTF8String(buf, unlockable); + + } + + @Override + public IMessage onMessage(MessageUnlockUnlockable message, MessageContext ctx) { + FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> handleMessage(message, ctx)); + return null; + } + + public IMessage handleMessage(MessageUnlockUnlockable message, MessageContext context) { EntityPlayer player = context.getServerHandler().player; - Skill skill = Skills.SKILLS.get(this.skill); - Unlockable unlockable = Skills.ALL_UNLOCKABLES.get(this.unlockable); + Skill skill = Skills.SKILLS.get(message.skill); + Unlockable unlockable = Skills.ALL_UNLOCKABLES.get(message.unlockable); PlayerData data = PlayerDataHandler.get(player); PlayerSkillInfo info = data.getSkillInfo(skill); - - if (!info.isUnlocked(unlockable) && info.getSkillPoints() >= unlockable.cost && data.matchStats(unlockable.getRequirements())) { + + if(!info.isUnlocked(unlockable) && info.getSkillPoints() >= unlockable.cost && data.matchStats(unlockable.getRequirements())) { info.unlock(unlockable); data.saveAndSync(); } - + return null; } } \ No newline at end of file diff --git a/src/main/java/codersafterdark/reskillable/network/PacketHandler.java b/src/main/java/codersafterdark/reskillable/network/PacketHandler.java new file mode 100644 index 00000000..c812dd7f --- /dev/null +++ b/src/main/java/codersafterdark/reskillable/network/PacketHandler.java @@ -0,0 +1,20 @@ +package codersafterdark.reskillable.network; + +import codersafterdark.reskillable.lib.LibMisc; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.relauncher.Side; + +public class PacketHandler { + public static SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(LibMisc.MOD_ID); + public static int ID = 0; + + public static void preInit() { + INSTANCE.registerMessage(MessageDataSync.class, MessageDataSync.class, ID++, Side.CLIENT); + INSTANCE.registerMessage(MessageDodge.class, MessageDodge.class, ID++, Side.SERVER); + INSTANCE.registerMessage(MessageLevelUp.class, MessageLevelUp.class, ID++, Side.SERVER); + INSTANCE.registerMessage(MessageLockedItem.class, MessageLockedItem.class, ID++, Side.CLIENT); + INSTANCE.registerMessage(MessageUnlockUnlockable.class, MessageUnlockUnlockable.class, ID++, Side.SERVER); + + + } +} From eb129df80845324a4e70ba41a32bbe02e9b24bf7 Mon Sep 17 00:00:00 2001 From: Jared Date: Sun, 11 Mar 2018 20:09:54 +0200 Subject: [PATCH 2/2] added license to RenderHelper --- .../reskillable/client/base/RenderHelper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java b/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java index 2912072f..a5f5bd1a 100644 --- a/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java +++ b/src/main/java/codersafterdark/reskillable/client/base/RenderHelper.java @@ -1,3 +1,13 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Jan 19, 2014, 5:40:38 PM (GMT)] + */ package codersafterdark.reskillable.client.base; import net.minecraft.client.Minecraft;