-
Posts
27 -
Joined
-
Last visited
Everything posted by Islandil
-
Ok. My new ItemRenderRegister public class ItemRenderRegister { public static void preInit() { ResourceLocation[] LOC = new ResourceLocation[LENGTH]; for (int i = 0; i < LOC.length; i++) { LOC[i] = new ResourceLocation(ITEM.getRegistryName().toString() + "_" + ITEM.getVar(i)); } ModelBakery.registerItemVariants(ITEM, LOC); ModelLoader.setCustomMeshDefinition(ITEM, new MESH()); } } I get null model for my icons. Using a breakpoint inside my getModelLocation I see the correct models being called and I checked the files names. So my problem is : why do I have no model for my icon in my inventory even if the right model is returned by getModelLocation ?
-
Client Proxy public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); ItemRenderRegister.preInit(); } ... } New ItemRenderRegister preInit public static void preInit() { register(ITEM); ResourceLocation[] LOC = new ResourceLocation[LENGTH]; for (int i = 0; i < LOC.length; i++) { LOC[i] = new ResourceLocation(ITEM.getRegistryName().toString() + "_" + ITEM.getVar(i)); } ModelBakery.registerItemVariants(ITEM, LOC); ModelLoader.setCustomMeshDefinition(ITEM, new MESH()); } Same result. All my item have the default texture. No call inside getModelLocation
-
ItemMeshDefinition implementation public class MESH implements ItemMeshDefinition { @Override public ModelResourceLocation getModelLocation(ItemStack itemStack) { if (itemStack != null && itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(TAG)) { return new ModelResourceLocation(ITEM.getRegistryName().toString() + "_" + ITEM.getVar(itemStack.getTagCompound().getString(TAG))); } return new ModelResourceLocation(ITEM.getRegistryName().toString()); } } ItemRenderRegister public class ItemRenderRegister { public static void preInit() { ResourceLocation[] LOC = new ResourceLocation[LENGTH]; for (int i = 0; i < LOC.length; i++) { LOC[i] = new ResourceLocation(ITEM.getRegistryName().toString() + "_" + ITEM.getVar(i)); } ModelBakery.registerItemVariants(ITEM, LOC); ModelLoader.setCustomMeshDefinition(ITEM, new MESH()); register(ITEM); } public static void init() { } private static void register(Item item) { register(item, 0, item.getRegistryName().toString()); } private static void register(Item item, int metadata, String file) { ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(file)); } } I declare some subtypes in my ITEM class with NBT used to define textures. With this code, all my ITEM have the default texture from this location : ITEM.getRegistryName().toString() Also I put breakpoints in : getModelLocation It is never called. If I move register(ITEM); from preInit to init then getModelLocation is called and the resources location are the correct ones but ITEM textures are now all null. I don't have any error in my stack trace.
-
Did this implementation (otherwise I was getting a out of bounds exception) @Nullable @Override public ItemStack decrStackSize(int index, int amount) { ItemStack stack; if (inventory[getLinkedIndex(index)].stackSize <= amount) { stack = inventory[getLinkedIndex(index)]; inventory[getLinkedIndex(index)] = null; } else { stack = inventory[getLinkedIndex(index)].splitStack(amount); if (inventory[getLinkedIndex(index)].stackSize == 0) { inventory[getLinkedIndex(index)] = null; } } return stack; } And it works. Thanks a lot !
-
Changed the getLinkedIndex to return the index parameter. Now isIndexInRange throw IndexOutOfBoundsException. Because the index given is 36 and 37 and is out side 0-1. private boolean isIndexInRange(int index) { index = getLinkedIndex(index); if (index >= 0 && index < getSizeInventory()) { return true; } else { throw new IndexOutOfBoundsException("Access index " + index + " is outside inventory index range, max " + getSizeInventory()); } } private int getLinkedIndex(int index) { return index; } It seems that the Container send the slot index and not the inventory index. Is there a problem in my Container ?
-
@Nullable @Override public ItemStack getStackInSlot(int index) { return indexInRange(index) ? inventory[getLinkedIndex(index)] : null; } private boolean indexInRange(int index) { index = getLinkedIndex(index); if (index >= 0 && index < getSizeInventory()) { return true; } else { throw new IndexOutOfBoundsException("Access index " + index + " is outside inventory index range, max " + getSizeInventory()); } } private int getLinkedIndex(int index) { return index - ItemContainer.INVENTORY_START; }
-
I implemented an item when shift right clicked open a GUI with the inventory and 2 more slot using mainly https://github.com/coolAlias/Forge_Tutorials/blob/master/InventoryItemTutorial.java as inspiration. After a day of debugging I don't understand why when I put item inside my custom inventory the quantity is double and why when I try to retrieve from the custom inventory the item are deleted. Here is a part of the Container @Nullable @Override public ItemStack transferStackInSlot(EntityPlayer player, int fromSlotIndex) { ItemStack previous = null; Slot fromSlot = (Slot) this.inventorySlots.get(fromSlotIndex); if (fromSlot != null && fromSlot.getHasStack()) { ItemStack current = fromSlot.getStack(); previous = current.copy(); if (fromSlotIndex < INVENTORY_START) { // Player to inventory if (!this.mergeItemStack(current, HOTBAR_START, INVENTORY_START, false)) return null; } else { // Inventory to player if (!this.mergeItemStack(current, INVENTORY_START, INVENTORY_START + inventory.getSizeInventory(), false)) return null; } if (current.stackSize == 0) { fromSlot.putStack((ItemStack) null); } else { fromSlot.onSlotChanged(); } if (current.stackSize == previous.stackSize) { return null; } fromSlot.onPickupFromSlot(player, current); } return previous; } @Nullable @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { if (slotId >= 0 && getSlot(slotId) != null && getSlot(slotId).getStack() == player.getHeldItem(EnumHand.MAIN_HAND)) { return null; } return super.slotClick(slotId, dragType, clickTypeIn, player); } and the IInventory @Nullable @Override public ItemStack decrStackSize(int index, int amount) { ItemStack stack = getStackInSlot(index); if (stack != null) { if (amount < stack.stackSize) { setInventorySlotContents(index, stack.splitStack(amount)); } else if (amount == stack.stackSize) { removeStackFromSlot(index); } else { throw new IllegalArgumentException("Cannot remove " + amount + " from a stack size of " + stack.stackSize); } } return stack; } // Remove an item from the inventory @Nullable @Override public ItemStack removeStackFromSlot(int index) { ItemStack removedStack = getStackInSlot(index); if (indexInRange(index)) { inventory[getLinkedIndex(index)] = null; } return removedStack; } // Add an item to the inventory @Override public void setInventorySlotContents(int index, @Nullable ItemStack stack) { if (isItemValidForSlot(index, stack)) { inventory[getLinkedIndex(index)] = stack; } markDirty(); } @Override public void markDirty() { for (int i = 0; i < getSizeInventory(); ++i) { if (inventory[i] != null && inventory[i].stackSize == 0) { inventory[i] = null; } } writeToNBT(inventoryItem.getTagCompound()); } // Get inventory content stored inside NBT tags on item stack public void readFromNBT(NBTTagCompound compound) { NBTTagList itemsList = compound.getTagList(NBT_TAG_LIST_KEY, Constants.NBT.TAG_COMPOUND); for (int i = 0; i < itemsList.tagCount(); ++i) { NBTTagCompound item = itemsList.getCompoundTagAt(i); int slot = item.getInteger(NBT_TAG_ITEM_SLOT_KEY); if (indexInRange(slot)) { inventory[slot] = ItemStack.loadItemStackFromNBT(item); } } } // Write inventory data to NBT tag list on item stack public void writeToNBT(NBTTagCompound compound) { NBTTagList itemsList = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (inventory[i] != null) { NBTTagCompound item = new NBTTagCompound(); item.setInteger(NBT_TAG_ITEM_SLOT_KEY, i); inventory[i].writeToNBT(item); itemsList.appendTag(item); } } compound.setTag(NBT_TAG_LIST_KEY, itemsList); }
-
[1.10.2] Performance issue with light moving with the player
Islandil replied to Islandil's topic in Modder Support
Sorry, I forget to add FPS in my first post. Event with moving the light source only when the player is below light level 10 drop FPS. And it make fast movement ugly, the light source doing jumps. Thanks for the help. I don't think it's possible to do without a core mod, so I drop the idea. -
[1.10.2] Performance issue with light moving with the player
Islandil replied to Islandil's topic in Modder Support
I use your light block and I experience the same fps drop. Do you experience the same thing on your side ? -
[1.10.2] Performance issue with light moving with the player
Islandil replied to Islandil's topic in Modder Support
Ok, so I implemented your code this way. It's basically a copy paste of your code inside the onUpdate of my helmet item. @Override public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { // Add invisible light block if the entity moving wear a tanned leather legs if(!world.isRemote && isHelmetOn(entity)) { NBTTagCompound lightCompound = stack.getSubCompound(LeatherArmorOverhaul.MODID + ":last_invisible_light", true); int lx = lightCompound.getInteger("lastLightX"); int ly = lightCompound.getInteger("lastLightY"); int lz = lightCompound.getInteger("lastLightZ"); BlockPos lastLightPos = new BlockPos(lx, ly, lz); if(entity instanceof EntityPlayer) { int nlx = MathHelper.floor_double(entity.posX); int nly = MathHelper.floor_double(entity.posY); int nlz = MathHelper.floor_double(entity.posZ); BlockPos newLightPos = new BlockPos(nlx, nly, nlz); boolean setLightBlock = false; if(nlx != lx || nly != ly || nlz != lz) { int d = (nlx - lx)*(nlx - lx)+(nly - ly)*(nly - ly)+(nlz - lz)*(nlz - lz); if(world.getBlockState(newLightPos).getLightValue() < 10) { if(d > 13) { //updating lighting info isn't fast if(ly >= 0 && ly < 256 && world.getBlockState(lastLightPos) == BlocksRegistry.invisibleLight.getDefaultState()) { world.setBlockToAir(lastLightPos); //System.out.println("Removed: " + lx + "," + ly + "," + lz); } //Set the light block at the player's feet (if possible) setLightBlock = true; } else { if(world.getBlockState(lastLightPos) != BlocksRegistry.invisibleLight.getDefaultState()) { if(world.isAirBlock(lastLightPos)) { //Reset the block if it disappeared world.setBlockState(lastLightPos, BlocksRegistry.invisibleLight.getDefaultState()); } else { //Set the new light block at the player's feet (if possible) setLightBlock = true; } } } } if(setLightBlock && nly >= 0 && nly < 256 && world.isAirBlock(newLightPos)) { world.setBlockState(newLightPos, BlocksRegistry.invisibleLight.getDefaultState()); lightCompound.setInteger("lastLightX",nlx); lightCompound.setInteger("lastLightY",nly); lightCompound.setInteger("lastLightZ",nlz); } } } } } Result: same. I lose ~10 fps when I wear the helmet. Conclusion: everybody as the same problem or it the block I am using that cause this drop in performance. Here is my invisible light block implementation : public class InvisibleLight extends Block { public InvisibleLight() { super(Material.AIR); setUnlocalizedName("invisible_light_block"); setRegistryName("invisible_light_block"); setCreativeTab(null); setHardness(0); setResistance(0); } // Black outline @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return null; } @Nullable @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) { return null; } @Override public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { return false; } @Override public int getLightOpacity(IBlockState state, IBlockAccess world, BlockPos pos) { return 0; } @Override public int getLightValue(IBlockState state) { return 15; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) { } @Nullable @Override public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { return null; } @SideOnly(Side.CLIENT) @Override public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } } -
[1.10.2] Performance issue with light moving with the player
Islandil replied to Islandil's topic in Modder Support
Actually I already looked at your code and use it to create mine. I don't understand why mine is so performance heavy ? And since you are here, I don't understand this part int d = (nlx - lx)*(nlx - lx)+(nly - ly)*(nly - ly)+(nlz - lz)*(nlz - lz); if(world.getBlockLightValue(nlx,nly,nlz) < 10) { if(d > 13) { //updating lighting info isn't fast if(ly >= 0 && ly < 256 && world.getBlock(lx, ly, lz) == BlockLight.instance) { world.setBlockToAir(lx, ly, lz); //System.out.println("Removed: " + lx + "," + ly + "," + lz); } //Set the light block at the player's feet (if possible) setLightBlock = true; } EDIT : Same problem with this implementation inside my helmet item @Override public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { // Add invisible light block if the entity moving wear a tanned leather legs if (!world.isRemote && isHelmetOn(entity)) { NBTTagCompound lastLightCompound = stack.getSubCompound(MYMOD.MODID + ":last_invisible_light", true); BlockPos entityPos = entity.getPosition(); BlockPos newLightPos = new BlockPos(MathHelper.floor_double(entityPos.getX()), MathHelper.floor_double(entityPos.getY()), MathHelper.floor_double(entityPos.getZ())); newLightPos = newLightPos.add(0, 1, 0); if (world.getBlockState(newLightPos).getLightValue() < 10) { if (lastLightCompound.hasKey("x") && lastLightCompound.hasKey("y") && lastLightCompound.hasKey("z")) { BlockPos lastLightPos = new BlockPos(lastLightCompound.getInteger("x"), lastLightCompound.getInteger("y"), lastLightCompound.getInteger("z")); if (newLightPos != lastLightPos && world.getBlockState(lastLightPos) == BlocksRegistry.invisibleLight.getDefaultState()) { world.setBlockToAir(lastLightPos); } } lastLightCompound.setInteger("x", newLightPos.getX()); lastLightCompound.setInteger("y", newLightPos.getY()); lastLightCompound.setInteger("z", newLightPos.getZ()); if (world.isAirBlock(newLightPos)) { world.setBlockState(newLightPos, BlocksRegistry.invisibleLight.getDefaultState()); } } } } -
[1.10.2] Performance issue with light moving with the player
Islandil replied to Islandil's topic in Modder Support
I put a intangible glowstone on the player head position when i wear my helmet. I move my code to onArmorTick and the performance issue is the same. Did I misunderstood ? -
When an entity is wearing an special helmet, I want to create light around him. I got big performance issue with this code @SubscribeEvent public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) { // Add invisible light block if the entity moving hold a torch helmet if (event.getEntity() != null && event.getEntity().getEntityWorld() != null && !event.getEntity().getEntityWorld().isRemote && event.getEntity().getArmorInventoryList() != null) { for (ItemStack itemStack : event.getEntity().getArmorInventoryList()) { if (itemStack != null && itemStack.getItem() != null && itemStack.getItem() == ItemsRegistry.torch_helmet) { NBTTagCompound lastLightCompound = itemStack.getSubCompound(MYMOD.MODID + ":last_invisible_light", true); BlockPos entityPos = event.getEntity().getPosition(); BlockPos newLightPos = new BlockPos(MathHelper.floor_double(entityPos.getX()), MathHelper.floor_double(entityPos.getY()), MathHelper.floor_double(entityPos.getZ())); newLightPos = newLightPos.add(0, 1, 0); if (event.getEntity().getEntityWorld().getBlockState(newLightPos).getLightValue() < 10) { if (lastLightCompound.hasKey("x") && lastLightCompound.hasKey("y") && lastLightCompound.hasKey("z")) { BlockPos lastLightPos = new BlockPos(lastLightCompound.getInteger("x"), lastLightCompound.getInteger("y"), lastLightCompound.getInteger("z")); if (newLightPos != lastLightPos && event.getEntity().getEntityWorld().getBlockState(lastLightPos) == BlocksRegistry.invisibleLight.getDefaultState()) { event.getEntity().getEntityWorld().setBlockToAir(lastLightPos); } } lastLightCompound.setInteger("x", newLightPos.getX()); lastLightCompound.setInteger("y", newLightPos.getY()); lastLightCompound.setInteger("z", newLightPos.getZ()); if (event.getEntity().getEntityWorld().isAirBlock(newLightPos)) { event.getEntity().getEntityWorld().setBlockState(newLightPos, BlocksRegistry.invisibleLight.getDefaultState()); } } break; } } } } Should I use another event ? improve my conditions ? prevent the code to be called more than x times by second ? something else ?