Procházet zdrojové kódy

added dynamic colored jewels

Kajetan Johannes Hammerle před 7 roky
rodič
revize
9fcd696f52

+ 2 - 1
src/main/java/me/km/ClientProxy.java

@@ -6,6 +6,7 @@ import me.km.blocks.ModBlocks;
 import me.km.blocks.cauldron.TileEntityCauldron;
 import me.km.entities.ModEntities;
 import me.km.items.ItemColoredSoup;
+import me.km.items.ItemJewel;
 import me.km.items.ModItems;
 import me.km.items.ModelCylinder;
 import me.km.items.ModelHat;
@@ -20,7 +21,6 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
 import net.minecraft.client.renderer.block.statemap.StateMapperBase;
 import net.minecraft.client.renderer.color.BlockColors;
 import net.minecraft.client.renderer.color.ItemColors;
-import net.minecraft.client.renderer.color.IBlockColor;
 import net.minecraft.client.renderer.entity.Render;
 import net.minecraft.client.resources.FoliageColorReloadListener;
 import net.minecraft.client.resources.GrassColorReloadListener;
@@ -108,6 +108,7 @@ public class ClientProxy extends CommonProxy
         
         ItemColors iColors = Minecraft.getMinecraft().getItemColors();
         iColors.registerItemColorHandler((ItemStack stack, int tintIndex) -> tintIndex > 0 ? -1 : ((ItemColoredSoup) stack.getItem()).getColor(stack), ModItems.coloredSoup);
+        iColors.registerItemColorHandler((ItemStack stack, int tintIndex) -> tintIndex > 0 ? -1 : ((ItemJewel) stack.getItem()).getColor(stack), ModItems.jewel);
         
         iColors.registerItemColorHandler((ItemStack stack, int tintIndex) ->
         {

+ 9 - 26
src/main/java/me/km/KajetansMod.java

@@ -11,6 +11,8 @@ import me.km.data.DataManager;
 import me.km.databank.DataBank;
 import me.km.dimensions.ModWorldGeneration;
 import me.km.dimensions.WorldData;
+import me.km.inventory.InventoryBase;
+import me.km.items.ModItems;
 import me.km.jobsystem.JobAPI;
 import me.km.networking.ModPacketHandler;
 import me.km.permissions.PermissionManager;
@@ -21,6 +23,7 @@ import me.km.scoreboard.ScoreboardAPI;
 import me.km.skills.SkillManager;
 import me.km.snuviscript.ScriptModule;
 import me.km.snuviscript.ScriptBank;
+import net.minecraft.item.ItemStack;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.util.text.TextFormatting;
 import net.minecraftforge.fluids.FluidRegistry;
@@ -94,7 +97,7 @@ public class KajetansMod
         DamageUtils.init();
         CapabilitiesEvents.init();
         
-        /*net.minecraftforge.common.MinecraftForge.EVENT_BUS.register(new Object()
+        net.minecraftforge.common.MinecraftForge.EVENT_BUS.register(new Object()
             {
                 @net.minecraftforge.fml.common.eventhandler.SubscribeEvent
                 public void wusi2(net.minecraftforge.event.ServerChatEvent e) 
@@ -103,37 +106,17 @@ public class KajetansMod
                     {
                         net.minecraft.entity.player.EntityPlayerMP p = e.getPlayer();
                         String[] parts = e.getMessage().split(" ");
-                        switch(parts[0])
-                        {
-                            case "0":
-                                ModPacketHandler.sendSeasonUpdate(p, (byte) 0);
-                                break;
-                            case "1":
-                                ModPacketHandler.sendSeasonUpdate(p, (byte) 1);
-                                break;
-                            case "2":
-                                ModPacketHandler.sendSeasonUpdate(p, (byte) 2);
-                                break;
-                        }
+                        int color = (Integer.parseInt(parts[0]) << 16) | (Integer.parseInt(parts[1]) << 8) | Integer.parseInt(parts[2]);
+                        ItemStack stack = new ItemStack(ModItems.jewel);
+                        ModItems.jewel.setColor(stack, color);
+                        p.addItemStackToInventory(stack);
                     }
                     catch(Exception ex)
                     {
                         ex.printStackTrace();
                     }
                 }
-                
-                @net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-                public void onPlayerFall(LivingEvent.LivingJumpEvent e)
-                {         
-                    System.out.println("WUSI");
-                    if(e.getEntityLiving() instanceof net.minecraft.entity.player.EntityPlayerMP)
-                    {
-                        System.out.println("SCALE");
-                        net.minecraft.entity.player.EntityPlayerMP p = (net.minecraft.entity.player.EntityPlayerMP) e.getEntityLiving();
-                        Utils.setVelocity(p, p.motionX, p.motionY * 2, p.motionZ);
-                    }
-                }
-            });*/
+            });
     }
     
     @Mod.EventHandler

+ 16 - 7
src/main/java/me/km/inventory/InventoryBase.java

@@ -8,15 +8,17 @@ import net.minecraft.item.ItemStack;
 public class InventoryBase extends InventoryBasic
 {
     private final Entity owner;
+    private final int allSlots;
     private final int rows;
     private final byte[] data;
     private final byte[] smallData;
     
-    public InventoryBase(String title, byte[] data, int slots, Entity owner) 
+    public InventoryBase(String title, byte[] data, int slots, int allSlots, Entity owner) 
     {
         super(title, true, slots);
         this.owner = owner;
-        this.rows = slots / 9 + (slots % 9 == 0 ? 0 : 1);
+        this.allSlots = allSlots;
+        this.rows = allSlots / 9 + (allSlots % 9 == 0 ? 0 : 1);
         this.data = data;
         this.smallData = deleteZeros(data);
     }
@@ -75,13 +77,13 @@ public class InventoryBase extends InventoryBasic
         super(title, true, Math.min(54, slots.length() - countZeros(slots)));
         this.owner = owner;
         
-        int slotAmount = Math.min(54, slots.length());
-        this.rows = slotAmount / 9 + (slotAmount % 9 == 0 ? 0 : 1);
-        
+        allSlots = Math.min(54, slots.length());
+        this.rows = allSlots / 9 + (allSlots % 9 == 0 ? 0 : 1);
+
         this.data = new byte[14];
         
         int id;
-        for(int i = 0; i < slotAmount; i++)
+        for(int i = 0; i < allSlots; i++)
         {
             id = Character.getNumericValue(slots.charAt(i));
             if(id > 3 || id < 0)
@@ -104,6 +106,7 @@ public class InventoryBase extends InventoryBasic
                     break;
             }
         }
+        
         this.smallData = deleteZeros(data);
     }
     
@@ -111,7 +114,8 @@ public class InventoryBase extends InventoryBasic
     {
         super(title, true, Math.max(9, Math.min(54, ((slots / 9) + ((slots % 9) == 0 ? 0 : 1)) * 9)));
         this.owner = owner;
-        this.rows = super.getSizeInventory() / 9;
+        this.allSlots = super.getSizeInventory();
+        this.rows = allSlots / 9;
         this.data = new byte[14];
         // default is 3 to every 2 bits
         Arrays.fill(this.data, (byte) 0xFF);
@@ -235,4 +239,9 @@ public class InventoryBase extends InventoryBasic
 
         return stack;
     }
+    
+    public int getAllSlots()
+    {
+        return allSlots;
+    }
 }

+ 51 - 0
src/main/java/me/km/items/ItemJewel.java

@@ -0,0 +1,51 @@
+package me.km.items;
+
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.common.capabilities.ICapabilityProvider;
+
+public class ItemJewel extends ItemBase
+{
+    public ItemJewel(String name, String local) 
+    {
+        super(name, local);
+        super.setCreativeTab(CreativeTabs.MATERIALS);
+    }
+
+    @Override
+    public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) 
+    {
+        getTagCompound(stack);
+        return null;
+    }  
+    
+    private NBTTagCompound getTagCompound(ItemStack stack)
+    {
+        NBTTagCompound com = stack.getTagCompound();
+        if(com == null)
+        {
+            com = new NBTTagCompound();
+            com.setInteger("color", 0xFFFFFF);
+            stack.setTagCompound(com);
+        }
+        else
+        {
+            if(!com.hasKey("color"))
+            {
+                com.setInteger("color", 0xFFFFFF);   
+            }
+        }
+        return com;
+    }
+    
+    public void setColor(ItemStack stack, int color)
+    {
+        getTagCompound(stack).setInteger("color", color);
+    }
+    
+    public int getColor(ItemStack stack)
+    {
+        return getTagCompound(stack).getInteger("color");
+    }
+}

+ 4 - 2
src/main/java/me/km/items/ModItems.java

@@ -232,6 +232,7 @@ public class ModItems
     public static ItemBase wolfFur; 
     public static ItemBlockSpecial campFire; 
     public static ItemBase coarseCloth;
+    public static ItemJewel jewel;
     
     // food
     public static ItemColoredSoup coloredSoup;
@@ -428,6 +429,7 @@ public class ModItems
         batWing = register(r, new ItemBase("bat_wing", "batWing").setCreativeTab(CreativeTabs.MATERIALS));
         wolfFur = register(r, new ItemBase("wolf_fur", "wolfFur").setCreativeTab(CreativeTabs.MATERIALS));
         coarseCloth = register(r, new ItemBase("coarse_cloth", "coarseCloth").setCreativeTab(CreativeTabs.MATERIALS));
+        jewel = register(r, new ItemJewel("jewel", "jewel"));
         
         // food
         coloredSoup = register(r, new ItemColoredSoup("colored_soup", "soupColored"));
@@ -468,7 +470,7 @@ public class ModItems
         
         try
         {
-            for(int i = 0; i < 10; i++)
+            for(int i = 0; i < 3; i++)
             {
                 System.out.println("DOING EVIL SHIT");
             }
@@ -488,7 +490,7 @@ public class ModItems
             PotionHelper.addContainerRecipe(potion, Items.GUNPOWDER, Items.SPLASH_POTION);
             PotionHelper.addContainerRecipe(splashPotion, Items.DRAGON_BREATH, Items.LINGERING_POTION);
             
-            for(int i = 0; i < 10; i++)
+            for(int i = 0; i < 3; i++)
             {
                 System.out.println("DONE WITH EVIL SHIT");
             }

+ 6 - 1
src/main/java/me/km/networking/CustomInventory.java

@@ -16,6 +16,7 @@ public class CustomInventory implements IMessage
     private int windowId;
     private String windowTitle;
     private byte slotCount;
+    private byte allSlots;
     private byte[] data;
     
     public CustomInventory() 
@@ -23,6 +24,7 @@ public class CustomInventory implements IMessage
         windowId = -1;
         windowTitle = "";
         slotCount = 9;
+        allSlots = 9;
         data = new byte[14];
     }
     
@@ -31,6 +33,7 @@ public class CustomInventory implements IMessage
         windowId = id;
         windowTitle = inv.getName();
         slotCount = (byte) inv.getSizeInventory();
+        allSlots = (byte) inv.getAllSlots();
         data = inv.getData();
     }
     
@@ -41,6 +44,7 @@ public class CustomInventory implements IMessage
         int length = buf.readInt();
         windowTitle = buf.readBytes(length).toString(StandardCharsets.UTF_8);
         slotCount = buf.readByte();
+        allSlots = buf.readByte();
         for(int i = 0; i < 14; i++)
         {
             data[i] = buf.readByte();
@@ -55,6 +59,7 @@ public class CustomInventory implements IMessage
         buf.writeInt(b.length);
         buf.writeBytes(b);
         buf.writeByte(slotCount);
+        buf.writeByte(allSlots);
         buf.writeBytes(data);
     }
 
@@ -68,7 +73,7 @@ public class CustomInventory implements IMessage
             EntityPlayerSP p = mc.player;
             mc.addScheduledTask(() -> 
             {
-                mc.displayGuiScreen(new CustomInventoryGui(p.inventory, new InventoryBase(m.windowTitle, m.data, m.slotCount, p)));
+                mc.displayGuiScreen(new CustomInventoryGui(p.inventory, new InventoryBase(m.windowTitle, m.data, m.slotCount, m.allSlots, p)));
                 p.openContainer.windowId = m.windowId;
             });
             return null;

+ 1 - 0
src/main/resources/assets/km/lang/en_US.lang

@@ -194,6 +194,7 @@ item.bundleHay.name=Hay Bundle
 item.batWing.name=Bat Wing
 item.wolfFur.name=Wolf Fur
 item.coarseCloth.name=Coarse Cloth
+item.jewel.name=Jewel
 
 item.soupColored.name=Stew
 item.apricot.name=Apricot

+ 6 - 0
src/main/resources/assets/km/models/item/jewel.json

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

binární
src/main/resources/assets/km/textures/items/jewel.png