Sfoglia il codice sorgente

added item stack display, basic texture atlas for the display

Kajetan Johannes Hammerle 6 anni fa
parent
commit
145378a815

+ 4 - 0
src/main/java/me/km/ClientEvents.java

@@ -1,6 +1,7 @@
 package me.km;
 
 import java.util.List;
+import me.km.networking.ItemStackDisplayGui;
 import me.km.networking.PlayerDisplayGui;
 import me.km.networking.PlayerHeadGui;
 import me.km.networking.StatusDisplayGui;
@@ -46,6 +47,7 @@ public class ClientEvents
             PlayerDisplayGui.INSTANCE.paint();
             StatusDisplayGui.INSTANCE.paint();
             PlayerHeadGui.INSTANCE.paint();
+            ItemStackDisplayGui.INSTANCE.paint();
         }
     }
     
@@ -55,6 +57,8 @@ public class ClientEvents
         PlayerDisplayGui.INSTANCE.clear();
         StatusDisplayGui.INSTANCE.clear();
         PlayerHeadGui.INSTANCE.clear();
+        ItemStackDisplayGui.INSTANCE.clear();
+        ItemStackDisplayGui.INSTANCE.setActive(false);
     }
     
     @SubscribeEvent

+ 17 - 6
src/main/java/me/km/KajetansMod.java

@@ -100,12 +100,23 @@ public class KajetansMod
                 {
                     try
                     {
-                        EntityPlayerMP p = e.getPlayer();
-                        EntityHuman human = new EntityHuman(p.world);
-                        human.setPosition(p.posX, p.posY, p.posZ);
-                        p.world.spawnEntity(human);
-                        
-                        human.setSkinName("e41b53353c7446e9a6c5dafc6334a477");
+                        String[] parts = e.getMessage().split(" ");
+                        if(parts[0].equals("clear"))
+                        {
+                            ModPacketHandler.clearItemStacks(e.getPlayer());
+                        }
+                        else if(parts[0].equals("active"))
+                        {
+                            ModPacketHandler.setItemStackActive(e.getPlayer(), true);
+                        }
+                        else if(parts[0].equals("inactive"))
+                        {
+                            ModPacketHandler.setItemStackActive(e.getPlayer(), false);
+                        }
+                        else
+                        {
+                            ModPacketHandler.setItemStackIndex(e.getPlayer(), Byte.parseByte(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
+                        }
                     }
                     catch(Exception ex)
                     {

+ 72 - 0
src/main/java/me/km/networking/ItemStackDisplay.java

@@ -0,0 +1,72 @@
+package me.km.networking;
+
+import io.netty.buffer.ByteBuf;
+import net.minecraft.client.Minecraft;
+import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
+import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
+import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
+
+public class ItemStackDisplay implements IMessage
+{
+    private byte index;
+    private int iconIndex;
+    private int count;
+    
+    public ItemStackDisplay() 
+    {
+        index = -1;
+        iconIndex = -1;
+        count = -1;
+    }
+    
+    public ItemStackDisplay(byte index, int iconIndex, int count) 
+    {
+        this.index = index;
+        this.iconIndex = iconIndex;
+        this.count = count;
+    }
+    
+    @Override
+    public void fromBytes(ByteBuf buf) 
+    {
+        index = buf.readByte();
+        iconIndex = buf.readInt();
+        count = buf.readInt();
+    }
+
+    @Override
+    public void toBytes(ByteBuf buf) 
+    {
+        buf.writeByte(index);
+        buf.writeInt(iconIndex);
+        buf.writeInt(count);
+    }
+
+    public static class Handler implements IMessageHandler<ItemStackDisplay, IMessage>
+    {
+        @Override
+        public IMessage onMessage(ItemStackDisplay message, MessageContext ctx) 
+        {
+            Minecraft mc = net.minecraft.client.Minecraft.getMinecraft();
+            mc.addScheduledTask(() -> 
+            {
+                switch(message.index)
+                {
+                    case -1:
+                        ItemStackDisplayGui.INSTANCE.setActive(true);
+                        break;
+                    case -2:
+                        ItemStackDisplayGui.INSTANCE.setActive(false);
+                        break;
+                    case -3:
+                        ItemStackDisplayGui.INSTANCE.clear();
+                        break;
+                    default: 
+                        ItemStackDisplayGui.INSTANCE.setIcon(message.index, message.iconIndex, message.count);
+                        break;
+                }
+            });
+            return null;
+        }
+    }
+}

+ 101 - 0
src/main/java/me/km/networking/ItemStackDisplayGui.java

@@ -0,0 +1,101 @@
+package me.km.networking;
+
+import me.km.KajetansMod;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.relauncher.Side;
+import net.minecraftforge.fml.relauncher.SideOnly;
+
+@SideOnly(Side.CLIENT)
+public class ItemStackDisplayGui extends Gui
+{
+    private static final ResourceLocation CUSTOM_ICONS = new ResourceLocation(KajetansMod.MODID, "textures/gui/itemstacks.png");
+    
+    public final static ItemStackDisplayGui INSTANCE = new ItemStackDisplayGui(Minecraft.getMinecraft());
+    
+    private final Minecraft mc;
+    private final int[] icons;
+    private boolean inactive = true;
+    
+    public ItemStackDisplayGui(Minecraft mc)
+    {
+        this.mc = mc;
+        this.icons = new int[27];
+        clear();
+    }  
+    
+    public void setActive(boolean active)
+    {
+        this.inactive = !active;
+    }
+    
+    public void setIcon(int index, int i, int count)
+    {
+        if(index >= 0 && index < 9)
+        {
+            index *= 3;
+            icons[index] = i < 48 ? 64 + ((i % 12) << 4) : (((i - 48) & 0xF) << 4);
+            icons[index + 1] = i < 48 ? (i / 12) << 4 : 64 + (((i - 48) >> 4) << 4);
+            icons[index + 2] = count;
+        }
+    }
+    
+    public final void clear()
+    {
+        for(int i = 0; i < 27; i += 3)
+        {
+            icons[i] = 64;
+            icons[i + 1] = 0;
+            icons[i + 2] = 0;
+        }
+    }
+    
+    public void paint()
+    {
+        if(inactive || mc.ingameGUI.getChatGUI().getChatOpen())
+        {
+            return;
+        }
+        
+        GlStateManager.enableBlend();
+        
+        mc.getTextureManager().bindTexture(CUSTOM_ICONS);
+        
+        ScaledResolution scaledresolution = new ScaledResolution(mc);
+        int screenWidth = scaledresolution.getScaledWidth();
+        int screenHeight = scaledresolution.getScaledHeight();
+        drawTexturedModalRect(screenWidth - 62, screenHeight - 62, 0, 0, 62, 62);
+        
+        int i = 0;
+        for(int y = 59; y > 0; y -= 20)
+        {
+            for(int x = 59; x > 0; x -= 20)
+            {
+                drawTexturedModalRect(screenWidth - x, screenHeight - y, icons[i], icons[i + 1], 16, 16);    
+                i += 3;
+            }
+        }
+        
+        GlStateManager.disableBlend();
+        
+        FontRenderer fr = mc.fontRenderer;
+        String s;
+        i = 2;
+        for(int y = 50; y > 0; y -= 20)
+        {
+            for(int x = 42; x > 0; x -= 20)
+            {
+                if(icons[i] != 0)
+                {
+                    s = String.valueOf(icons[i]);
+                    fr.drawStringWithShadow(s, (float)(screenWidth - x - fr.getStringWidth(s)), (float)(screenHeight - y), 16777215);
+                } 
+                i += 3;
+            }
+        }
+    }
+}

+ 20 - 0
src/main/java/me/km/networking/ModPacketHandler.java

@@ -25,6 +25,7 @@ public class ModPacketHandler
         INSTANCE.registerMessage(SeasonUpdate.Handler.class, SeasonUpdate.class, id++, Side.CLIENT);
         INSTANCE.registerMessage(StatusDisplay.Handler.class, StatusDisplay.class, id++, Side.CLIENT);
         INSTANCE.registerMessage(PlayerHead.Handler.class, PlayerHead.class, id++, Side.CLIENT);
+        INSTANCE.registerMessage(ItemStackDisplay.Handler.class, ItemStackDisplay.class, id++, Side.CLIENT);
     }
     
     public static void sendToDisplay(EntityPlayerMP p, byte action, byte index, String text)
@@ -93,4 +94,23 @@ public class ModPacketHandler
     {
         INSTANCE.sendTo(new PlayerHead(action, index, name, x, y, scale), p);
     }
+    
+    //--------------------------------------------------------------------------
+    // item stack display
+    //--------------------------------------------------------------------------
+    
+    public static void setItemStackIndex(EntityPlayerMP p, byte index, int iconIndex, int count)
+    {
+        INSTANCE.sendTo(new ItemStackDisplay(index, iconIndex, count), p);
+    }
+    
+    public static void setItemStackActive(EntityPlayerMP p, boolean active)
+    {
+        INSTANCE.sendTo(new ItemStackDisplay(active ? (byte) -1 : (byte) -2, -1, -1), p);
+    }
+    
+    public static void clearItemStacks(EntityPlayerMP p)
+    {
+        INSTANCE.sendTo(new ItemStackDisplay((byte) -3, -1, -1), p);
+    }
 }

+ 2 - 2
src/main/java/me/km/networking/StatusDisplayGui.java

@@ -67,8 +67,8 @@ public class StatusDisplayGui extends Gui
         }
     }
     
-    private TreeMap<Integer, LineData> strings;
-    private Minecraft mc;
+    private final TreeMap<Integer, LineData> strings;
+    private final Minecraft mc;
     
     public StatusDisplayGui(Minecraft mc)
     {

+ 37 - 0
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -1583,6 +1583,43 @@ public class MinecraftFunctions
             return Void.TYPE; 
         });
         
+        // ---------------------------------------------------------------------  
+        // ItemStack-Display-Bibliothek   
+        // ---------------------------------------------------------------------  
+        parser.registerFunction("stacks.set", (sc, in) -> 
+        {  
+            byte index = in[1].getByte(sc);
+            if(index < 0 || index >= 9)
+            {
+                throw new IllegalArgumentException("index must be beetween 0 and 8, given: " + index);
+            }
+            int iconIndex = in[2].getInt(sc);
+            int count = in[3].getInt(sc);
+            doForGroup(in[0].get(sc), sc, p -> ModPacketHandler.setItemStackIndex((EntityPlayerMP) p, index, iconIndex, count));
+            return Void.TYPE; 
+        }); 
+        parser.registerFunction("stacks.clearindex", (sc, in) -> 
+        {  
+            byte index = in[1].getByte(sc);
+            if(index < 0 || index >= 9)
+            {
+                throw new IllegalArgumentException("index must be beetween 0 and 8, given: " + index);
+            }
+            doForGroup(in[0].get(sc), sc, p -> ModPacketHandler.setItemStackIndex((EntityPlayerMP) p, index, 0, 0));
+            return Void.TYPE; 
+        }); 
+        parser.registerFunction("stacks.clear", (sc, in) -> 
+        {  
+            doForGroup(in[0].get(sc), sc, p -> ModPacketHandler.clearItemStacks((EntityPlayerMP) p));
+            return Void.TYPE; 
+        });
+        parser.registerFunction("stacks.setactive", (sc, in) -> 
+        {  
+            boolean active = in[1].getBoolean(sc);
+            doForGroup(in[0].get(sc), sc, p -> ModPacketHandler.setItemStackActive((EntityPlayerMP) p, active));
+            return Void.TYPE; 
+        });
+        
         // ---------------------------------------------------------------------  
         // Head-Bibliothek   
         // ---------------------------------------------------------------------  

+ 1 - 9
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -398,15 +398,7 @@ public class ScriptEvents extends ModuleListener
             sc.setVar("cancel", e.isCanceled()); 
         }, (sc) -> 
         {
-            try
-            {
-                sheep.setSheared(sc.getVar("entity_sheared").getBoolean(sc));
-                e.setCanceled(sc.getVar("cancel").getBoolean(sc)); 
-            }
-            catch(Exception ex)
-            {
-                KajetansMod.scripts.logger.print("invalid var in 'entity_shear' event", ex, null, sc.getName(), sc, sc.getActiveRealLine());
-            }
+            simpleCancel(sc, e, "entity_shear");
         });
     }
        

+ 1 - 1
src/main/resources/assets/km/models/item/gear.json

@@ -1,6 +1,6 @@
 {
     "parent": "item/generated",
     "textures": {
-        "layer0": "km:items/gear"
+        "layer0": "km:items/icons/gear"
     }
 }

BIN
src/main/resources/assets/km/textures/gui/itemstacks.png


+ 0 - 0
src/main/resources/assets/km/textures/items/gear.png → src/main/resources/assets/km/textures/items/icons/gear.png