-
Posts
94 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Zacomat
-
Thank you very much! It was easier than I expected. I added @Override public boolean isEnchantable(ItemStack itemstack) { return true; } too. And implemented @Override public boolean canApplyAtEnchantingTable(ItemStack itemstack, Enchantment e) { return e == Enchantments.FISHING_LUCK || e == Enchantments.FISHING_SPEED || e == Enchantments.UNBREAKING; } @Override public int getEnchantmentValue(ItemStack itemstack) { return 2; } this way.
-
Hi all! I'd like to make my fishingnets enchantable as fishing rods. It's a new topic for me. Can anyone point me in the right direction? Thx!
-
Hi everyone! I have block entity that implements WorldlyContainer. And I have a BlockEntityRenderer that draws the contained objects. In all methods where the content is changed, I update the client with level.sendBlockUpdated (worldPosition, state, state, Block.UPDATE_CLIENTS) The methods in question are public void setItem (int index, ItemStack it) and public ItemStack removeItem (int index, int amount) And everything seems to work very well!!! But when I put a hopper under my block entity, a mess happens! The removeItem and setItem methods are called over and over to try to fill the hopper and the messages between the server and the client are wasted. Is there a way to prevent it? How can I do? Thank you all!
-
1.19 How to access BlockEntity data from ContainerScreen
Zacomat replied to Zacomat's topic in Modder Support
Thank you very much ! -
1.19 How to access BlockEntity data from ContainerScreen
Zacomat replied to Zacomat's topic in Modder Support
First of all thanks for the quick reply! The problem is that I want to show in the renderTooltip of my screen some data that is already synchronized in my client side blockentity. The method is AbstractContainerScreen.renderTooltip(PoseStack pose, int mousex, int mousey) @Override protected void renderTooltip(PoseStack pose, int mousex, int mousey) { if (menu.getCarried().isEmpty() && hoveredSlot != null && hoveredSlot.hasItem()) { this.renderTooltip(pose, hoveredSlot.getItem(), mousex, mousey); } else if (mousex > leftPos + 94 && mousex < leftPos + 94 + 17 && mousey > topPos + 51 - 17 && mousey < topPos + 51) { List<Component> lines = new ArrayList<Component>(); MyBlockEntity mbe = null;//I dont know how to get a reference to my block entity CompoundTag tag = new CompoundTag(); mbe.saveAdditional(tag); lines.add(Component.literal("tag=" + tag)); lines.add(Component.literal("pos=" + mbe.getBlockPos())); lines.add(Component.literal("line 3")); lines.add(Component.literal("line 4")); lines.add(Component.literal("line 5")); this.renderComponentTooltip(pose, lines, mousex, mousey); } } -
Hi all! I want to show some data from my BlockEntity in the method renderTooltip of my screen that implements AbstractContainerScreen. But i dont know how to get a reference to the BlockEntity of the block clicched to open the screen. Any suggestions? Thx
-
Hi all I am making a mod that creates a map. In my Recipe class in the ItemStack assemble (CraftingContainer) method I can compute all the data, but I don't think the Level.getFreeMapId method should also be called. I do this in onItemCrafted (ItemCraftedEvent e): I add the map id in the compound tag, effectively modifying the result of the recipe. And I don't know how to intercept right shift-click on the result item. When quick crafting the resulting map does not have a map id. In this case the onItemCrafted (ItemCraftedEvent e) method does not work properly. I'm using the 1.19 41.1.0 version atm. The way around the problem I made is the following: I search in the player's inventory for a slot with an item equal to the one I just crafted and replace it with the one returned by the event. @SubscribeEvent public void onItemCrafted(ItemCraftedEvent e) { Player player = e.getEntity(); ItemStack crafting = e.getCrafting(); CompoundTag tag = crafting.getTag(); if (tag == null || !tag.contains("my_tag")) { return; } Inventory inventory = player.getInventory(); int slot = inventory.findSlotMatchingItem(crafting); if (slot != -1) { inventory.setItem(slot, crafting); } tag.remove("my_tag"); ... }
-
I found the error: In the tile entity when i create the ccntainer in the method createMenu I have to pass the IInventory of the tile entity or the tile entity will not be notified @Override protected Container createMenu(int id, PlayerInventory player) { LOGGER.info("HELLO FROM createMenu id=" + id + " player=" + player); //the third parameter "this" is the IInventory implemented by the tile entity // ChestContainer container = ChestContainer.createGeneric9X3(id, player, this); ContainerGcmBookshelf container2 = ContainerGcmBookshelf.createGeneric9X3(id, player, this); return container2; }
-
Hi all! I'm trying to make a container bookshelf in my mod. I made my block and my tile entity. In the tile entity i overrided the method createMenu: @Override protected Container createMenu(int id, PlayerInventory player) { ChestContainer container = ChestContainer.createGeneric9X3(id, player); return container; } At this point all works fine, when i harvest my block all items are saved and when i place it are restored. When i move itemstack from an inventory to an other it seems to work. Now i want to make my container accept only books. I want to filter items inserted. The ChestContainer class instances his Slot where isItemValid returns always true. To replace the slot class I tried to create my own container, copied fron ChestContainer, and my own slot class where i overrided boolean isItemValid(ItemStack stack): package com.polipo.bookshelf.container; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; /** * Copied from ChestContainer to replace the slots instances in the constructor. * * @author giacomo * */ public class ContainerGcmBookshelf extends Container { private final IInventory lowerChestInventory; private final int numRows; private ContainerGcmBookshelf(ContainerType<?> type, int id, PlayerInventory player, int rows) { this(type, id, player, new Inventory(9 * rows), rows); } public static ContainerGcmBookshelf createGeneric9X1(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X1, id, player, 1); } public static ContainerGcmBookshelf createGeneric9X2(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X2, id, player, 2); } public static ContainerGcmBookshelf createGeneric9X3(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X3, id, player, 3); } public static ContainerGcmBookshelf createGeneric9X4(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X4, id, player, 4); } public static ContainerGcmBookshelf createGeneric9X5(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X5, id, player, 5); } public static ContainerGcmBookshelf createGeneric9X6(int id, PlayerInventory player) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X6, id, player, 6); } public static ContainerGcmBookshelf createGeneric9X3(int id, PlayerInventory player, IInventory blockEntity) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X3, id, player, blockEntity, 3); } public static ContainerGcmBookshelf createGeneric9X6(int id, PlayerInventory player, IInventory blockEntity) { return new ContainerGcmBookshelf(ContainerType.GENERIC_9X6, id, player, blockEntity, 6); } public ContainerGcmBookshelf(ContainerType<?> type, int id, PlayerInventory playerInventoryIn, IInventory p_i50092_4_, int rows) { super(type, id); assertInventorySize(p_i50092_4_, rows * 9); this.lowerChestInventory = p_i50092_4_; this.numRows = rows; p_i50092_4_.openInventory(playerInventoryIn.player); int i = (this.numRows - 4) * 18; for (int j = 0; j < this.numRows; ++j) { for (int k = 0; k < 9; ++k) { //Replace new Slot whit my GcmBookshelfSlot this.addSlot(new GcmBookshelfSlot(p_i50092_4_, k + j * 9, 8 + k * 18, 18 + j * 18)); } } for (int l = 0; l < 3; ++l) { for (int j1 = 0; j1 < 9; ++j1) { this.addSlot(new Slot(playerInventoryIn, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i)); } } for (int i1 = 0; i1 < 9; ++i1) { this.addSlot(new Slot(playerInventoryIn, i1, 8 + i1 * 18, 161 + i)); } } /** * Determines whether supplied player can use this container */ @Override public boolean canInteractWith(PlayerEntity playerIn) { return this.lowerChestInventory.isUsableByPlayer(playerIn); } /** * Handle when the stack in slot {@code index} is shift-clicked. Normally this * moves the stack between the player inventory and the other inventory(s). */ @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index < this.numRows * 9) { if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } } return itemstack; } /** * Called when the container is closed. */ @Override public void onContainerClosed(PlayerEntity playerIn) { super.onContainerClosed(playerIn); this.lowerChestInventory.closeInventory(playerIn); } /** * Gets the inventory associated with this chest container. * * @see #field_75155_e */ public IInventory getLowerChestInventory() { return this.lowerChestInventory; } @OnlyIn(Dist.CLIENT) public int getNumRows() { return this.numRows; } } package com.polipo.bookshelf.container; import com.polipo.bookshelf.config.BookshelfConfig; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; public class GcmBookshelfSlot extends Slot { public GcmBookshelfSlot(IInventory inventoryIn, int index, int xPosition, int yPosition) { super(inventoryIn, index, xPosition, yPosition); } /** * Check if the stack is allowed to be placed in this slot, used for armor slots * as well as furnace fuel. */ @Override public boolean isItemValid(ItemStack stack) { return BookshelfConfig.canInsert(stack); } } But now nothing works When i move items from an inventory to the others they disappear either if they are books or not. Maybe i should change transferStackInSlot? But how? Is this correct way to make a container to filter items to be inserted? Thanks a lot of your help
-
Hi all! In my mod I load some parameters from config file. All works fine and I tested synchronizations from server to client. In my Mod class constructor i call: //register the ForgeConfigSpec ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, BookshelfConfig.server_config); //here is where we load parameters BookshelfConfig.loadConfig(BookshelfConfig.server_config, FMLPaths.CONFIGDIR.get().resolve(MODID + "-server.toml").toString()); Then in the ModConfigEvent handler i build some data structures... @SubscribeEvent public static void onModConfigEvent(ModConfigEvent event) { LOGGER.info("HELLO FROM ModConfigEvent " + event + " " + event.getPhase()); //prepare tables BookshelfConfig.setupItems(); } Is this the correct way to load config? Where should registration and data loading be done?
-
I'm trying the RightClickBlock event. In the mod class i have a method for handling the event: this is the class declaration: @Mod(ExampleMod.MODID) @Mod.EventBusSubscriber public class ExampleMod { ... and this is my static method in ExampleMod class: @SubscribeEvent public static void onBlockRichtClick(RightClickBlock e) { LOGGER.info("HELLO FROM onBlockRichtClick " + e + " phase=" + e.getPhase() + " isRemote=" + e.getPlayer().world.isRemote); if (e.getPlayer().world.isRemote) { LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.silkRequired=" + BookshelfConfig.silkRequiredValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.items=" + BookshelfConfig.itemsValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.books=" + BookshelfConfig.booksValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.silkRequired=" + BookshelfConfig.silkRequired); LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.items=" + BookshelfConfig.items); LOGGER.info("onBlockRichtClick world.isRemote=true bookshelves.books=" + BookshelfConfig.books); } else { LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.silkRequired=" + BookshelfConfig.silkRequiredValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.items=" + BookshelfConfig.itemsValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.books=" + BookshelfConfig.booksValue.get().toString()); LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.silkRequired=" + BookshelfConfig.silkRequired); LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.items=" + BookshelfConfig.items); LOGGER.info("onBlockRichtClick world.isRemote=false bookshelves.books=" + BookshelfConfig.books); } } but this is the logger output: [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: HELLO FROM onBlockRichtClick net.minecraftforge.event.entity.player.PlayerInteractEvent$RightClickBlock@5b160208 phase=NORMAL isRemote=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.silkRequired=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.items=[minecraft:painting, minecraft:paper, minecraft:filled_map, minecraft:item_frame, minecraft:map] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.books=[minecraft:book, minecraft:writable_book, minecraft:written_book, minecraft:enchanted_book] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.silkRequired=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.items=[item_frame, paper, filled_map, painting, map] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.books=[written_book, writable_book, book, enchanted_book] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: HELLO FROM onBlockRichtClick net.minecraftforge.event.entity.player.PlayerInteractEvent$RightClickBlock@36ec4071 phase=NORMAL isRemote=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.silkRequired=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.items=[minecraft:painting, minecraft:paper, minecraft:filled_map, minecraft:item_frame, minecraft:map] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.books=[minecraft:book, minecraft:writable_book, minecraft:written_book, minecraft:enchanted_book] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.silkRequired=true [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.items=[item_frame, paper, filled_map, painting, map] [08:20:29] [Render thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=true bookshelves.books=[written_book, writable_book, book, enchanted_book] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: HELLO FROM onBlockRichtClick net.minecraftforge.event.entity.player.PlayerInteractEvent$RightClickBlock@78512fcc phase=NORMAL isRemote=false [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.silkRequired=true [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.items=[minecraft:painting, minecraft:paper, minecraft:filled_map, minecraft:item_frame, minecraft:map] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.books=[minecraft:book, minecraft:writable_book, minecraft:written_book, minecraft:enchanted_book] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.silkRequired=true [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.items=[item_frame, paper, filled_map, painting, map] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.books=[written_book, writable_book, book, enchanted_book] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: HELLO FROM onBlockRichtClick net.minecraftforge.event.entity.player.PlayerInteractEvent$RightClickBlock@5b675fb6 phase=NORMAL isRemote=false [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.silkRequired=true [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.items=[minecraft:painting, minecraft:paper, minecraft:filled_map, minecraft:item_frame, minecraft:map] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.books=[minecraft:book, minecraft:writable_book, minecraft:written_book, minecraft:enchanted_book] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.silkRequired=true [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.items=[item_frame, paper, filled_map, painting, map] [08:20:29] [Server thread/INFO] [co.ex.ex.ExampleMod/]: onBlockRichtClick world.isRemote=false bookshelves.books=[written_book, writable_book, book, enchanted_book] Why there are 4 different instance of the event?
-
Hi all! I have a mod that registers this recipe in the init method (when FMLInitializationEvent is fired): ItemStack output = new ItemStack(Items.WRITTEN_BOOK); NBTTagCompound compound = new NBTTagCompound(); output.setTagCompound(compound); compound.setTag("title", new NBTTagString(new TextComponentTranslation("giacomostravelogue.title").getFormattedText())); compound.setBoolean("giacomostravelogue", true); ResourceLocation name = new ResourceLocation(MODID + ":travelogue_recipe"); ResourceLocation group = null; Ingredient ingredient1 = Ingredient.fromItem(Items.COMPASS); Ingredient ingredient2 = Ingredient.fromItem(Items.WRITABLE_BOOK); GameRegistry.addShapelessRecipe(name, group, output, ingredient1, ingredient2); As you can see the tag "title" has a value that depends on the language. Is there a way to put in the json recipe something like that?
-
When a player connects to a server, the config file of the client may be different from that of the server. To avoid undesired behaviours I have to synchronise the client configuration values with the server ones and reset client variables with them. What is the best way to do it? Should i send a custom packet to client with server values in ServerConnectionFromClientEvent?
-
That works fine! Thank you!
-
I'm porting my mods from 1.11.2 to 1.12.2 and i found this issue. When I move the mouse over the items in the container slots there are no tooltip shown. What can it be? Where i should investigate? Thx
-
Thx! Now all work! But there are 2 things: 1) In the output the server warn: Dangerous alternative prefix `minecraft` for name `compass` ... 2) I had to make the entry "item.item.compass.name=Compass" in the lang file
-
What is the name? Should i use public static final Item myCompass = new ItemMyCompass().setRegistryName("minecraft:compass").setUnlocalizedName("compass").setCreativeTab(CreativeTabs.MISC);
-
Do i have to provide models and textures even if they are equals to original ones or there is a way to replace only items as before?
-
I cannot figure out how to use substitution aliases in 1.12.2. In 1.11 in the register items event i used @SubscribeEvent public void onRegisterItem(RegistryEvent.Register<Item> event) { try { GameRegistry.addSubstitutionAlias("minecraft:compass", GameRegistry.Type.ITEM, GiacomosTeleport.myCompass); GameRegistry.addSubstitutionAlias("minecraft:map", GameRegistry.Type.ITEM, GiacomosTeleport.myEmptyMap); GameRegistry.addSubstitutionAlias("minecraft:filled_map", GameRegistry.Type.ITEM, GiacomosTeleport.myFilledyMap); } catch (ExistingSubstitutionException e) { e.printStackTrace(); } } But in 1.12 how can it be done? thx for help
-
Ok thanks it worked! But there are some biomes that are not required for the advancement like "Ice Plains Spikes" and are not listed in the AdvancementProgress#getCompletedCriteria(). I'd like to have a complete list containing all visited biomes. How could it be done? Thx
-
I need the list of all required biomes for the advancement Adventuring Time and the list of all explored biomes by the player. In 1.11 i used: Set<Biome> required = Sets.newHashSet(Biome.EXPLORATION_BIOMES_LIST); JsonSerializableSet explored = (JsonSerializableSet) player.getStatFile().getProgress(AchievementList.EXPLORE_ALL_BIOMES); but in 1.12 i don't know how to do. Can you help please? Thx
-
Item Substitution Aliases break recipes and trades
Zacomat replied to Zacomat's topic in Modder Support
I have a new question How do i make my items work in the enchanting table without overriding Item.isEnchantable(ItemStack)? -
Item Substitution Aliases break recipes and trades
Zacomat replied to Zacomat's topic in Modder Support
Yes, you are right! I implemented the teleport with events you suggested and it works fine! There are still two things I do not know how to do: 1) How to set an animation during item usage (using compasses with the bow animation was funny) 2) When an empty map is rightclicked i want to add to the resulting filled map a tag that contains the coordinates where the map was created to use for teleport back there -
Item Substitution Aliases break recipes and trades
Zacomat replied to Zacomat's topic in Modder Support
So the suggestion is to avoid using substitution aliases... And I also think so, but in ItemMyCompass I have other stuff for handling enchantments: only enchanted compasses and maps can be used to teleport. And the player should perform and animation during the cast. The question is how to make substitution aliases work with trades and recipes? -
Item Substitution Aliases break recipes and trades
Zacomat replied to Zacomat's topic in Modder Support
This is a teleport mod. The player can teleport by using a compass or a map. In the method Item.onItemUseFinish is where the teleport is implemented.