-
Posts
25 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Sweetmimike's Achievements

Tree Puncher (2/8)
1
Reputation
-
Thanks for your answers. I managed to use a server config and to override the function @Override public int getMaxDamage(ItemStack stack) { return ServerConfigs.MOB_SHARD_DURABILITY.get(); } But now, the durability bar seems to be hidden since I removed the .durability(int) in the properties. How can I show it again ? EDIT : I found the solution to display it again. I just had to use the .durability(int) function on the properties, and the value taken for the durability is the one that come from the configs.
-
Sweetmimike started following Problem on setting nbt tag on Item , [1.18.2] Config field does not work , 1.18.2 - Server crashes on registering ItemProperties and 2 others
-
Hello, I'm currently working on a mod and I'm using a configuration field to determine the durability of an item. But I don't understand why when I change the config in the .toml file, the durability of the item stay at the default value. Here is how I set the durability (MOB_SHARD_DURABILITY) : /** * Manager for the mod items */ public class ItemManager { public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, PerfectMobFarm.MODID); // Use of CommonConfig public static final RegistryObject<Item> MOB_SHARD = ITEMS.register("mob_shard", () -> new MobShard(new Item.Properties().tab(PerfectMobFarm.PERFECT_MOB_FARM_TAB), CommonConfigs.MOB_SHARD_DURABILITY.get())); public static void register(IEventBus eventBus) { ITEMS.register(eventBus); } } ///////////////// // Item class // //////////////// public MobShard(Properties pProperties, int pDurability) { this(pProperties.durability(pDurability)); } Of course I have others config fields and they work properly.
-
1.18.2 - Server crashes on registering ItemProperties
Sweetmimike replied to Sweetmimike's topic in Modder Support
Thank you very much ! -
Hello ! When I try to run a server with my mod, an error occurs and make the server crashes. It seems that the error happens on the client setup and more precisely when I try to register a new ItemProperties. private void clientSetup(final FMLClientSetupEvent event) { MenuScreens.register(MenuManager.MOB_FARM_MENU.get(), MobFarmScreen::new); ItemBlockRenderTypes.setRenderLayer(BlockManager.IRON_MOB_FARM.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(BlockManager.GOLD_MOB_FARM.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(BlockManager.DIAMOND_MOB_FARM.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(BlockManager.EMERALD_MOB_FARM.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(BlockManager.NETHERITE_MOB_FARM.get(), RenderType.cutout()); event.enqueueWork(() -> { ItemProperties.register(ItemManager.MOB_SHARD.get(), new ResourceLocation(PerfectMobFarm.MODID, "completed"), ((pStack, pLevel, pEntity, pSeed) -> { CompoundTag nbtData = pStack.getTag(); if (nbtData != null && nbtData.contains(NbtTagsName.KILLED_COUNT)) { return nbtData.getInt(NbtTagsName.KILLED_COUNT) == CommonConfigs.MOB_SHARD_KILL_NEEDED.get() ? 1.0F : 0.0F; } return 0.0F; })); ItemProperties.register(ItemManager.ADVANCED_MOB_SHARD.get(), new ResourceLocation(PerfectMobFarm.MODID, "completed"), ((pStack, pLevel, pEntity, pSeed) -> { CompoundTag nbtData = pStack.getTag(); if (nbtData != null && nbtData.contains(NbtTagsName.KILLED_COUNT)) { return nbtData.getInt(NbtTagsName.KILLED_COUNT) == CommonConfigs.MOB_SHARD_KILL_NEEDED.get() ? 1.0F : 0.0F; } return 0.0F; })); }); } When I comment the event.enqueueWork block, the server doesn't crash. Just below is the error stack trace.
-
Sweetmimike changed their profile photo
-
[1.18.2] Render an entity at a certain position
Sweetmimike replied to Sweetmimike's topic in Modder Support
Right. I modified the code just as follows final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); Entity entityToSpawn = pBlockEntity.getEntityToDisplay(); if(entityToSpawn == null || entityToSpawn.getType() != entityType) { LOGGER.debug("NEED TO CREATE A NEW ENTITY"); entityToSpawn = entityType.create(pBlockEntity.getLevel()); pBlockEntity.setEntityToDisplay(entityToSpawn); } float scale = 0.3f; pPoseStack.pushPose(); pPoseStack.translate(0.5f, 1f, 0.5f); pPoseStack.scale(scale, scale, scale); entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880); pPoseStack.popPose(); So the entity I want to display is stored in a block entity -
When do you want it to detect the block (when you walk/click/jump) ?
-
Hi @OR1ON! The best thing you can do is to find a tutorial about creating block entities and/or look at the minecraft furnace code and mimic it.
-
[1.18.2] Render an entity at a certain position
Sweetmimike replied to Sweetmimike's topic in Modder Support
I finally solved the problem ! If anyone is interested on how render an entity, you can find the code I used just below final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); Entity entityToSpawn = entityType.create(pBlockEntity.getLevel()); float scale = 0.3f; pPoseStack.pushPose(); pPoseStack.translate(0.5f, 1f, 0.5f); pPoseStack.scale(scale, scale, scale); entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880); pPoseStack.popPose(); -
Hey ! I'm trying to render an entity (for example a cow) just above a custom block entity. Of course, the renderer is correctly registered. final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); final BlockRenderDispatcher dispatcher = this.context.getBlockRenderDispatcher(); // pPoseStack.pushPose(); // pPoseStack.translate(0.5f, 0.5f, 0.5f); // dispatcher.renderSingleBlock(Blocks.GLASS.defaultBlockState(), pPoseStack, pBufferSource, pPackedLight, pPackedOverlay, // EmptyModelData.INSTANCE); // pPoseStack.popPose(); Entity entityToSpawn = EntityType.COW.create(pBlockEntity.getLevel()); // LOGGER.debug("ENTITY TO SPAWN " + entityToSpawn.getName()); // pPoseStack.pushPose(); pPoseStack.translate(0.5f, 2f, 0.5f); pPoseStack.scale(2f, 2f, 2f); entityDispatcher.render(entityToSpawn, pBlockEntity.getBlockPos().getX(), pBlockEntity.getBlockPos().getY(), pBlockEntity.getBlockPos().getZ(), 0.0f, pPartialTick, pPoseStack, pBufferSource, pPackedLight); pPoseStack.popPose(); Is there something I do not correctly ?
-
What do you mean about that ? Do you think it is possible to apply a looting effect to the LootContext ?
-
Yes indeed And for the looting enchant ? It seems to not be considered
-
Hello, Thank you for your anwsers, I finally succeeded. I have just one more question : Why in the code below, the parameter TOOL is not considered ? Indeed, when I try to generate loot from a cow, it generates beef whereas I added a parameter TOOL with a diamond sword with fire aspect, so It should generate Steak. ResourceLocation loc = new ResourceLocation(resourcePath); LootTables ltManager = this.getLevel().getServer().getLootTables(); LootTable lt = ltManager.get(loc); ItemStack sword = new ItemStack(Items.DIAMOND_SWORD); sword.enchant(Enchantments.MOB_LOOTING, 3); sword.enchant(Enchantments.FIRE_ASPECT, 1); Vec3 position = new Vec3(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ()); LootContext.Builder builder = (new LootContext.Builder((ServerLevel) this.level)) .withParameter(LootContextParams.TOOL, sword) .withParameter(LootContextParams.ORIGIN, position); LootContext ctx = builder.create(LootContextParamSets.FISHING); List<ItemStack> generated = lt.getRandomItems(ctx);
-
Hello, I just wanted to know if it exists a way of generating programmatically a loot when you have the loot table. In my case I've got the loot table from a resouce location but I don't understand how I need to use the LootContext ect ... Here is my code : ResourceLocation loc = new ResourceLocation(resourcePath); LootTables ltManager = this.getLevel().getServer().getLootTables(); LootTable lt = ltManager.get(loc); LootContextParamSet ltps = lt.getParamSet(); LootContext.Builder builder = new LootContext.Builder((ServerLevel) this.level); List<ItemStack> generated = lt.getRandomItems(builder.create(ltps));
-
Hello, I dont really understand why the nbt tag in the code below is not attached to the item. @Override public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget, InteractionHand pUsedHand) { if (pPlayer.getLevel().isClientSide()) { if (pInteractionTarget instanceof Mob mob) { System.out.println("ITEMSTACK " + pStack); CompoundTag nbtTag = null; System.out.println("nbt tag " + nbtTag); if (!(pStack.hasTag())) { nbtTag = new CompoundTag(); CompoundTag nbtMobTag = new CompoundTag(); mob.save(nbtMobTag); nbtTag.put("mob", nbtMobTag); System.out.println("IN NBT NULL " + nbtTag); pStack.setTag(nbtTag); System.out.println("AFTER TAG SET " + pStack.hasTag()); pPlayer.sendMessage(new TextComponent("Shard used on " + mob.getDisplayName().getString()), pPlayer.getUUID()); } else { nbtTag = pStack.getTag(); System.out.println("item has tag"); System.out.println(nbtTag.contains("mob")); } } } return InteractionResult.PASS; } @Override public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) { CompoundTag nbtTag = pStack.getTag(); if (nbtTag != null) { if (nbtTag.contains("mob")) { Mob targetMob = null; targetMob.deserializeNBT(nbtTag.getCompound("mob")); pTooltipComponents.add(new TextComponent("Mob : " + targetMob.getDisplayName().getString())); } } } Everytime I right click with the Item on a LivingEntity, It goes on the if(!pStack.hasTag()), but It shouldn't because we set the tag on the first right click on an Entity Do you have a solution ?
-
Thanks it works !