Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

bibouche_

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by bibouche_

  1. @Override public ActionResultType onBlockActivated( BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (worldIn != null && !worldIn.isRemote()) { TileEntity te = worldIn.getTileEntity(pos); Item playerItem = player.getHeldItemMainhand() .getItem(); if (te instanceof CelestialPowerPedestalTileEntity) { if (((CelestialPowerPedestalTileEntity) te).isFillable() && playerItem == ModItems.CELESTIAL_POWER_EYE.get()) { ItemStack stack = player.getHeldItemMainhand(); ((CelestialPowerPedestalTileEntity) te).insertItem(0, stack, false); player.getHeldItemMainhand().shrink(1); Alcamod.LOGGER.info(((CelestialPowerPedestalTileEntity) te).getStackInSlot(0)); return ActionResultType.SUCCESS; } if (!((CelestialPowerPedestalTileEntity) te).isFillable()) { player.addItemStackToInventory(((CelestialPowerPedestalTileEntity) te).getStackInSlot(0)); ((CelestialPowerPedestalTileEntity) te).extractItem(0, 1, false); return ActionResultType.SUCCESS; } } } return ActionResultType.CONSUME; } In the tile entity: public Item getItem() { return getStackInSlot(0).getItem(); } @Override public ItemStack getStackInSlot( int index) { return this.items.get(index); } @Nonnull @Override public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate) { if (!this.isFillable()) return stack; return ItemStack.EMPTY; } @Nonnull @Override public ItemStack extractItem( int slot, int amount, boolean simulate) { if (this.isFillable()) return ItemStack.EMPTY; else return getStackInSlot(0); } @Override public int getSlotLimit( int slot) { return getStackInSlot(0).getMaxStackSize(); } @Override public boolean isItemValid( int slot, @Nonnull ItemStack stack) { return true; }
  2. Hi, I don't really know if my title is correct or appropriate but I don't know how to describe it. I created a TileEntity which you can fill only with one item, and which has an inventory size of 1, so it takes only one item in the inventory. My problem is that when I want to set the item in the slot, with items.set(0, ItemStack) (items is a NonNullList of ItemStacks), it is not setting it, and I don't know why because I did exactly the same thing with my other TileEntities (with more slots) and it works perfectly, so I don't know if it's a problem with NonNullList of size 1 or f I need a container (because I think I don't need a container if I won't add a gui but I may be wrong), or anything else. So please someone help me ? My TileEntity class: public class CelestialPowerPedestalTileEntity extends LockableLootTileEntity implements ISidedInventory { public static final int slots = 1; public NonNullList <ItemStack> items = NonNullList.withSize(slots, ItemStack.EMPTY); public CelestialPowerPedestalTileEntity() { super(ModTileEntities.CELESTIAL_POWER_PEDESTAL_TILE_ENTITY.get()); } @Override protected ITextComponent getDefaultName() { return new TranslationTextComponent("container." + Alcamod.ModID + ".celestial_power_pedestal"); } @Override public ITextComponent getDisplayName() { return new TranslationTextComponent("Celestial Power Pedestal"); } @Override protected Container createMenu( int id, PlayerInventory player) { return null; } @Override protected NonNullList <ItemStack> getItems() { return this.items; } public Item getItem() { return this.items.get(0).getItem(); } public ItemStack getStack() { return this.items.get(0); } @Override protected void setItems( @Nonnull NonNullList <ItemStack> itemsIn) { this.items = itemsIn; } public void setStack(ItemStack stack) { this.items.set(0, stack); } @Override public int getSizeInventory() { return 1; } public void read( BlockState state, CompoundNBT nbt) { super.read( state, nbt); this.items = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); if (!this.checkLootAndRead(nbt)) { ItemStackHelper.loadAllItems(nbt, this.items); } } @Nonnull @Override public CompoundNBT write( CompoundNBT compound) { super.write(compound); if (!checkLootAndWrite(compound)) { ItemStackHelper.saveAllItems(compound, this.items); } return compound; } @Nonnull @Override public <T> LazyOptional <T> getCapability( Capability <T> cap, Direction side) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(cap, LazyOptional.of(() -> (IItemHandler) this.items)); } @Nonnull @Override public int[] getSlotsForFace( Direction side) { return new int[] {0}; } @Override public boolean canInsertItem( int index, ItemStack stack, @Nullable Direction direction) { return stack.getItem() == ModItems.CELESTIAL_POWER_EYE.get(); } @Override public boolean canExtractItem( int index, ItemStack stack, Direction direction) { return true; } public boolean isFillable() { return getItem() != ModItems.CELESTIAL_POWER_EYE.get(); } } My Block class: public class CelestialPowerPedestal extends Block { public CelestialPowerPedestal() { super(Properties.create(Material.IRON) .hardnessAndResistance(40, 80) .sound(SoundType.BASALT) .harvestLevel(3) .harvestTool(ToolType.PICKAXE)); } public VoxelShape getShape( BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return CelestialPowerPedestalVoxelShapes.SHAPE; } @Override public boolean hasTileEntity(BlockState state) { return true; } @Nullable @Override public TileEntity createTileEntity( BlockState state, IBlockReader world) { return ModTileEntities.CELESTIAL_POWER_PEDESTAL_TILE_ENTITY.get().create(); } @Override public ActionResultType onBlockActivated( BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (worldIn != null && !worldIn.isRemote()) { TileEntity te = worldIn.getTileEntity(pos); Item playerItem = player.getHeldItemMainhand() .getItem(); if (te instanceof CelestialPowerPedestalTileEntity) { if (((CelestialPowerPedestalTileEntity) te).isFillable() && playerItem == ModItems.CELESTIAL_POWER_EYE.get()) { ItemStack stack = player.getHeldItemMainhand(); ((CelestialPowerPedestalTileEntity) te).setStack(stack); player.getHeldItemMainhand().shrink(1); return ActionResultType.SUCCESS; } if (!((CelestialPowerPedestalTileEntity) te).isFillable()) { player.addItemStackToInventory(((CelestialPowerPedestalTileEntity) te).getStack()); ((CelestialPowerPedestalTileEntity) te).setStack(ItemStack.EMPTY); return ActionResultType.SUCCESS; } } } return ActionResultType.CONSUME; } @Override public void onReplaced( BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof CelestialPowerPedestalTileEntity && state.getBlock() != newState.getBlock()) { InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory) tile); worldIn.updateComparatorOutputLevel(pos, this); } if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) { worldIn.removeTileEntity(pos); } } } The targeted code block where I put the action when the player right click the block: @Override public ActionResultType onBlockActivated( BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (worldIn != null && !worldIn.isRemote()) { TileEntity te = worldIn.getTileEntity(pos); Item playerItem = player.getHeldItemMainhand() .getItem(); if (te instanceof CelestialPowerPedestalTileEntity) { if (((CelestialPowerPedestalTileEntity) te).isFillable() && playerItem == ModItems.CELESTIAL_POWER_EYE.get()) { ItemStack stack = player.getHeldItemMainhand(); ((CelestialPowerPedestalTileEntity) te).setStack(stack); player.getHeldItemMainhand().shrink(1); return ActionResultType.SUCCESS; } if (!((CelestialPowerPedestalTileEntity) te).isFillable()) { player.addItemStackToInventory(((CelestialPowerPedestalTileEntity) te).getStack()); ((CelestialPowerPedestalTileEntity) te).setStack(ItemStack.EMPTY); return ActionResultType.SUCCESS; } } } return ActionResultType.CONSUME; }
  3. You mean adding an IntReferenceHolder and doing TrackInt like I did for currentSmeltTime ?
  4. I deleted the @OnlyIn but it is not fixing the issue. Here is my container class: public class ForgeContainer extends Container { public final ForgeTileEntity te; private final IWorldPosCallable canInteractWithCollable; public FunctionalIntreferenceHolder currentSmeltTime; public ForgeContainer(final int windowId, final PlayerInventory playerInv, final ForgeTileEntity te) { super(ModContainers.FORGE_CONTAINER.get(), windowId); this.te = te; this.canInteractWithCollable = IWorldPosCallable.of(te.getWorld(), te.getPos()); // Forge Inv this.addSlot(new ForgeUpgradableSlot(te, 0, 42, 34)); this.addSlot(new ForgeFuelSlot( te, 1, 42, 63)); this.addSlot(new ForgeCompressorSlot(te, 2, 81, 7)); this.addSlot(new ForgeOutputSlot(te, 3, 117, 34)); this.trackInt(currentSmeltTime = new FunctionalIntreferenceHolder(() -> this.te.currentSmeltTime, time -> this.te.currentSmeltTime = time)); // Player Inv for (int row = 0; row < 3; row++) { for (int col = 0; col < 9; col++) { this.addSlot(new Slot(playerInv, col + row * 9 + 9, 8 + col * 18, 119 + (row * 18))); } } // Player HotBar for (int col = 0; col < 9; col++) { this.addSlot(new Slot(playerInv, col, 8 + col * 18, 177)); } } public ForgeContainer(final int windowId, final PlayerInventory playerInv, final PacketBuffer data) { this(windowId, playerInv, getTileEntity(playerInv, data)); } private static ForgeTileEntity getTileEntity(final PlayerInventory playerInv, final PacketBuffer data) { Objects.requireNonNull(playerInv, "player inventory cannot be null"); Objects.requireNonNull(data, "packet buffer cannot be null"); final TileEntity te = playerInv.player.world.getTileEntity(data.readBlockPos()); if (te instanceof ForgeTileEntity) { return (ForgeTileEntity) te; } throw new IllegalStateException("Tile Entity is not correct"); } @Override public boolean canInteractWith( PlayerEntity playerIn) { return isWithinUsableDistance(canInteractWithCollable, playerIn, ModBlocks.FORGE.get()); } @Override public ItemStack transferStackInSlot( PlayerEntity playerIn, int index) { ItemStack stack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack stack1 = slot.getStack(); stack = stack1.copy(); if (index < ForgeTileEntity.slots - 1 && !this.mergeItemStack(stack1, ForgeTileEntity.slots, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } if (!this.mergeItemStack(stack1, 0, ForgeTileEntity.slots, false)) { return ItemStack.EMPTY; } if (stack1.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } } return stack; } public int getSmeltProgressionScaled() { return this.currentSmeltTime.get() != 0 && this.te.smeltTime != 0 ? this.currentSmeltTime.get() * 47 / this.te.smeltTime : 0; } }
  5. Hi everyone, for my mod I wanted to do a custom furnace, everything works fine except the progression bar, indeed in the screen class, where I use the drawGuiContainerBackgroundLayer( ) function I put a blit with my progression bar, the problem I have is that I think it draws the texture once and then it is not updating, even if for the width I inserted a dynamic value that gives the width to display depending on the currentSmeltTime out of the MaxSmeltTime of the cooking. So my question would be : How can I make this updating and redrawing when the value changes ? Here is the function which is called : @Override protected void drawGuiContainerBackgroundLayer( MatrixStack matrixStack, float partialTicks, int mousex, int mousey) { RenderSystem.color4f(1f, 1f, 1f, 1f); this.minecraft.textureManager.bindTexture(FORGE_GUI); this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); int l = this.container.getSmeltProgressionScaled(); this.blit(matrixStack, this.guiLeft + 64, this.guiTop + 40, 176, 0, l + 1, 4); } my problem is in the two last lines, may someone help me please ? the getSmeltProgressionScaled( ) function (in my container class) : @OnlyIn(Dist.CLIENT) public int getSmeltProgressionScaled() { return this.te.currentSmeltTime != 0 && this.te.smeltTime != 0 ? this.te.currentSmeltTime * 47 / this.te.smeltTime : 0; } Thanks you for your help
  6. Alright, unnesting the two nested classes seems to fix the issue, but I don't really understand why they are not loading btw
  7. The two nested classes are for organisation, not to mix up the type and the serializer. But ur right I can change the names to FORGING_TYPE and FORGING_SERIALIZER. I register it in my main class : ModRecipes.recipe_serializers.register(bus);
  8. Hi everyone, I wanted to create a new type of recipe for my mod, So I created a new class for the recipe, with the serializer, I have no problems at all, just that I have an error saying "Parsing error loading recipe alcamod:argentite_sword_forging" and "Invalid or unsupported recipe type 'alcamod:forging'". I made sure to register the serializer with the deferred Register, registered the DeferredRegister with the mod event bus and the recipe Type with IRecipeType.register(Alcamod.ModID + "forging") I also made sure that my recipe json is correct, with the right type and so on. But the game is still throwing the same error. Can someone please help me ? I looked everywhere on the forums but found nothing that solved my problem. Here is my Serializer : public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<ForgeRecipe> { @Override public ForgeRecipe read( ResourceLocation recipeId, JsonObject json) { Ingredient base = Ingredient.deserialize(JSONUtils.getJsonObject(json, "base")); Ingredient compressor = Ingredient.deserialize(JSONUtils.getJsonObject(json, "compressor")); ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result")); return new ForgeRecipe(recipeId, base, compressor, result); } @Nullable @Override public ForgeRecipe read( ResourceLocation recipeId, PacketBuffer buffer) { Ingredient base = Ingredient.read(buffer); Ingredient compressor = Ingredient.read(buffer); ItemStack result = buffer.readItemStack(); return new ForgeRecipe(recipeId, base, compressor, result); } @Override public void write( PacketBuffer buffer, ForgeRecipe recipe) { recipe.base.write(buffer); recipe.compressor.write(buffer); buffer.writeItemStack(recipe.result); } } My JSON recipe: { "type": "alcamod:forging", "base": { "item": "minecraft:netherite_sword" }, "compressor": { "item": "alcamod:tools_compressor_tier_1" }, "result": { "item": "alcamod:argentite_sword" } } And the registering: public class ModRecipes { public static final DeferredRegister <IRecipeSerializer<?>> recipe_serializers = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, Alcamod.ModID); public static class Types { public static final IRecipeType<ForgeRecipe> FORGING = IRecipeType.register(Alcamod.ModID + "forging"); } public static class Serializers { public static final RegistryObject<IRecipeSerializer<?>> FORGING = recipe_serializers.register("forging", ForgeRecipe.Serializer::new); } } Also the recipe: public class ForgeRecipe implements IRecipe <IInventory> { private final Ingredient base; private final Ingredient compressor; private final ItemStack result; private final ResourceLocation recipeId; public ForgeRecipe(ResourceLocation recipeId, Ingredient base, Ingredient compressor, ItemStack result) { this.recipeId = recipeId; this.base = base; this.compressor = compressor; this.result = result; } @Override public boolean matches( IInventory inv, World worldIn) { return this.base.test(inv.getStackInSlot(0)) && this.compressor.test(inv.getStackInSlot(2)); } @Override public ItemStack getCraftingResult( IInventory inv) { return this.result.copy(); } @Override public boolean canFit( int width, int height) { return width * height >= 3; } @Override public ResourceLocation getId() { return this.recipeId; } @Override public ItemStack getRecipeOutput() { return this.result; } @Override public ItemStack getIcon() { return new ItemStack(ModBlocks.FORGE_ITEM.get()); } @Override public IRecipeSerializer <?> getSerializer() { return ModRecipes.Serializers.FORGING.get(); } @Override public IRecipeType <?> getType() { return ModRecipes.Types.FORGING; } } Thank you for your help, and if I missed something please tell me (Edit: added the recipe class)
  9. Hmmm, yeah it might be a solution, just need to learn more about it now πŸ˜‚. Thanks, I’ll work it out πŸ™ƒ
  10. Hi, for my mod optimisation purposes, I just wanted to know if there is a way to execute parts of an event which is client side, but in server-side, like for example an event fired only in Dist.CLIENT, but for one part of the event, like breaking blocks, execute it server-side. Idk if I am clear, but I hop you understood my question πŸ˜…. Thanks you very much πŸ™ƒ
  11. Ok, I got that, but it it still not working πŸ˜…, plus I don't understand the interest of the while( sky() == null);
  12. It crahses my game as soon as it execute that line of code, it may be because I don't know what to put as "PacketBuffer data" πŸ˜…, have you got any piece of idea ? Here is the line that make it crash : player.changeDimension(DimensionManager.registerOrGetDimension(DimensionInit.ORES_DIM.getId(), DimensionInit.ORES_DIM.get(), null, true);
  13. Ok, that seems decent, I’m gonna try to do this this afternoon, Ima tell you if it works
  14. Hmm nope, I haven’y tried that, however I am not sure if I can get a dimension with biome provider πŸ˜•
  15. My dimension class extends Dimension, but when I get it with DefferedRegister, it returns a ModDimension, not a DimensionType, and that's the point
  16. Hi, I am currently trying to make a block that teleports the player in my custom dimension, and I runned into an issue. Indeed, for my player.changeDimension(), I need a DimensionType, and with my DefferedRegistrer I can just get a ModDimension, so I wanted to know if there is a way to get it as a DimensionType, otherwise it's quiet annoying as I can't make it to work Thanks
  17. Oh thank you so much, it finally works, I'm so happy I made the Stream.forEach() loop, and that's all
  18. yup, I did that, but it isn't working, and when I print the pos for every element of the stream, it prints the same position at all, and I don't understand why
  19. Ok, so I do need to convert it to a list ? But is there a problem with my foreach loop ? when I make it sysout position for every pos of the stream, it prints the same position at all, and I don't really understand why
  20. Ok so I think I figured it out, with a simple foreach loop, but I still can't make it works πŸ˜‘ I made this : @SubscribeEvent public static void onBlockBreakEvent(BlockEvent.BreakEvent e) { PlayerEntity playerIn = e.getPlayer(); Block block = e.getState().getBlock(); IWorld world = e.getWorld(); if (e.getState().getBlock() instanceof OreBlock) { int radius = 3; int baseX = e.getPos().getX() - radius; int baseY = e.getPos().getY() - radius; int baseZ = e.getPos().getZ() - radius; int finalX = e.getPos().getX() + radius; int finalY = e.getPos().getY() + radius; int finalZ = e.getPos().getZ() + radius; BlockPos firstPos = new BlockPos(baseX, baseY, baseZ); BlockPos secondPos = new BlockPos(finalX, finalY, finalZ); Stream<BlockPos> blockList = BlockPos.getAllInBox(firstPos, secondPos); for ( BlockPos pos : blockList.collect(Collectors.toList()) ) { if (world.getBlockState(pos).getBlock() == block) { world.destroyBlock(pos, true); } } } }
  21. Okkk, thanks, indeed it was a pain making a such loop πŸ˜…, I am trying to find how BlockPos.getAllInBox(...) works, but I don't fully understand Have you got any advice ? πŸ˜… I mean, I found out how to create the Stream with the two positions, but how can I use the Stream it creates ?
  22. Hi, I made a pickaxe in my mod that I actually want it to break ore veins more easily, so I made a blockbreakevent, and then a script that checks for every block around the ore you broke if there are any blocks of the same type, and if there are, then break them. My script is actually not working, and I don't really know why πŸ˜…, so I post this for any help, I would really appreciate it. Thanks ! Here is my event : @SubscribeEvent public static void onBreakEventWithPickaxe(BlockEvent.BreakEvent e) { PlayerEntity playerIn = e.getPlayer(); Item pickaxe = ModItems.NETHER_STAR_PICKAXE.get(); Block block = e.getState().getBlock(); IWorld world = e.getWorld(); if (e.getState().getBlock() instanceof OreBlock && playerIn.getHeldItemMainhand().getItem() == pickaxe) { int radius = 3; int height = 6; int posX = e.getPos().getX() - radius; int posY = e.getPos().getY() - radius; int posZ = e.getPos().getZ() - (height / 2); for (int i = 0; i < radius * 2 * radius * 2 * height; i++) { BlockPos pos = new BlockPos(posX, posY, posZ); if (world.getBlockState(pos).getBlock() == block) { world.destroyBlock(pos, true); } posX++; if (posX == radius * 2 + 1) { posY++; posX = e.getPos().getX() - radius; } if (posY == radius * 2 + 1) { posZ++; posY = e.getPos().getY() - radius; posX = e.getPos().getX() - radius; } } } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.