Jump to content

Sweetmimike

Members
  • Posts

    28
  • 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

Tree Puncher (2/8)

1

Reputation

  1. Hello, I'm currently updated my mod from 1.18.2 version to 1.20.2, and I was used to use the "FakePlayerFactory" that seems to have disappear in the 1.20.2 version. This is how I created fake players. protected LivingEntity getOrCreateFakePlayer() { if (fakePlayer == null) { fakePlayer = FakePlayerFactory.getMinecraft((ServerLevel) this.level); } return fakePlayer; } These fake players where used as parameters for creating a "LootParams" object like this : protected LootParams constructLootParams(Mob mob) { Vec3 position = new Vec3(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ()); Player fakePlayer = (Player) getOrCreateFakePlayer(); return new LootParams.Builder((ServerLevel) this.level).withParameter(LootContextParams.ORIGIN, position) .withParameter(LootContextParams.THIS_ENTITY, mob) .withParameter(LootContextParams.DAMAGE_SOURCE, fakePlayer.damageSources().genericKill()) .withParameter(LootContextParams.KILLER_ENTITY, fakePlayer) .withParameter(LootContextParams.LAST_DAMAGE_PLAYER, fakePlayer) .create(LootContextParamSets.ENTITY); } So I would like to know if it is still possible to create fake players and if yes how ? And if not, how am I supposed to create the loot params in order to make it like it is a player that killed the entity ? Thanks,
  2. Hello ! I'm in trouble with passing data from a ContainerMenu class to ContainerScreen class. Indeed as you can see just below, I'm using the function "getProgressed()" but this function seems to not having access to this.data as it returns always the same thing : 0. But if I call "this.data.get(0)" in the overrided function "stillValid" from the same class, it returns the correct integer. public class MobFarmMenu extends AbstractContainerMenu { /** Clicked entity */ private final IronMobFarmEntity farmEntity; /** Current level */ private final Level level; private final ContainerData data; public MobFarmMenu(int pContainerId, Inventory inv, FriendlyByteBuf extraData) { this(pContainerId, inv, inv.player.level.getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(2)); } public MobFarmMenu(int pContainerId, Inventory inv, BlockEntity entity, ContainerData data) { super(MenuManager.MOB_FARM_MENU.get(), pContainerId); checkContainerSize(inv, 1); farmEntity = ((IronMobFarmEntity) entity); this.level = inv.player.level; this.data = data; System.out.println("IN CONSTRUCTOR " + data.get(1)); addPlayerInventory(inv); addPlayerHotbar(inv); this.farmEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler -> { this.addSlot(new MobShardSlot(handler, 0, 80, 20)); }); } public int getProgress() { int current = this.data.get(0); int max = this.data.get(1); int progressBarSize = 41; // System.out.println("current : " + current + " || max : " + max + "|| data" + this.data.getCount()); System.out.println("DATA " + this.data.get(1)); return max != 0 ? current * progressBarSize / max : 0; } // CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons // must assign a slot number to each of the slots used by the GUI. // For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar. // Each time we add a Slot to the container, it automatically increases the slotIndex, which means // 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8) // 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35) // 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8) private static final int HOTBAR_SLOT_COUNT = 9; private static final int PLAYER_INVENTORY_ROW_COUNT = 3; private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9; private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT; private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT; private static final int VANILLA_FIRST_SLOT_INDEX = 0; private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT; // THIS YOU HAVE TO DEFINE! private static final int TE_INVENTORY_SLOT_COUNT = 1; // must be the number of slots you have! @Override public ItemStack quickMoveStack(Player playerIn, int index) { Slot sourceSlot = slots.get(index); if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM ItemStack sourceStack = sourceSlot.getItem(); ItemStack copyOfSourceStack = sourceStack.copy(); // Check if the slot clicked is one of the vanilla container slots if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) { // This is a vanilla container slot so merge the stack into the tile inventory if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)) { return ItemStack.EMPTY; // EMPTY_ITEM } } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) { // This is a TE slot so merge the stack into the players inventory if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) { return ItemStack.EMPTY; } } else { System.out.println("Invalid slotIndex:" + index); return ItemStack.EMPTY; } // If stack size == 0 (the entire stack was moved) set slot contents to null if (sourceStack.getCount() == 0) { sourceSlot.set(ItemStack.EMPTY); } else { sourceSlot.setChanged(); } sourceSlot.onTake(playerIn, sourceStack); return copyOfSourceStack; } @Override public boolean stillValid(Player pPlayer) { System.out.println("DATA1 " + this.data.get(1)); // return stillValid(ContainerLevelAccess.create(level, farmEntity.getBlockPos()), // pPlayer, BlockManager.IRON_MOB_FARM.get()); if (!(this.level.getBlockEntity(this.farmEntity.getBlockPos()).getBlockState().getBlock() instanceof IronMobFarm)) { return false; } else { return !(pPlayer.distanceToSqr((double) this.farmEntity.getBlockPos().getX() + 0.5D, (double) this.farmEntity.getBlockPos().getY() + 0.5D, (double) this.farmEntity.getBlockPos().getZ() + 0.5D) > 64.0D); } } private void addPlayerInventory(Inventory playerInventory) { for (int i = 0; i < 3; ++i) { for (int l = 0; l < 9; ++l) { this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 51 + i * 18)); } } } private void addPlayerHotbar(Inventory playerInventory) { for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 109)); } } } I don't get why the function "getProgressed" can't have access to the right values of to "this.data".
  3. 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.
  4. 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.
  5. 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.
  6. 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
  7. When do you want it to detect the block (when you walk/click/jump) ?
  8. 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.
  9. 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();
  10. 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 ?
  11. What do you mean about that ? Do you think it is possible to apply a looting effect to the LootContext ?
  12. Yes indeed And for the looting enchant ? It seems to not be considered
  13. 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);
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.