Jump to content

MIssNalgas

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by MIssNalgas

  1. Forgot to say. When i found out i tried using #world.sendBlockUpdated() to update the block but if i do that the TER dissapears xdd. I will be crying in the bathroom if you need me
  2. Thank you for answering. But that didn't resolve my issue xd. I found out though that the tileentity does update when i reload the chunk
  3. package com.example.examplemod; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.container.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.LockableTileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.NonNullList; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import javax.annotation.Nullable; public class ChestingTableTileEntity extends LockableTileEntity implements ITickableTileEntity { private NonNullList<ItemStack> items = NonNullList.withSize(10, ItemStack.EMPTY); private int openCount = 0; private float openness = 0.0f; public ChestingTableTileEntity(TileEntityType<?> entityType) { super(entityType); ExampleMod.LOGGER.info("Created tile entity chest: "+this); } public ChestingTableTileEntity() { this(ExampleMod.myChestTileEntity.get()); ExampleMod.LOGGER.info("fechasimportantes"); } @Override protected Container createMenu(int i, PlayerInventory inventory) { return new MyChestContainer(inventory, i, this); } @Override public void tick() { if (this.openCount > 0 && this.openness < 1.0f || this.openCount == 0 && this.openness > 0.0f) { if (this.openCount > 0) { this.openness += 0.1f; } else { this.openness -= 0.1f; } if (this.openness < 0.0f) { this.openness = 0.0f; } } } @OnlyIn(Dist.CLIENT) public float getOpenness() { return this.openness; } public void load(BlockState state, CompoundNBT nbt) { super.load(state, nbt); this.items = NonNullList.withSize(10, ItemStack.EMPTY); ItemStackHelper.loadAllItems(nbt, this.items); } public CompoundNBT save(CompoundNBT nbt) { super.save(nbt); ItemStackHelper.saveAllItems(nbt, this.items); return nbt; } @Override protected ITextComponent getDefaultName() { return new StringTextComponent("Chesting table"); } @Override public int getContainerSize() { return this.items.size(); } @Override public boolean isEmpty() { for (ItemStack item : this.items) { if (!item.isEmpty()) { return false; } } return true; } @Override public ItemStack getItem(int i) { return this.items.get(i); } @Override public ItemStack removeItem(int i1, int i2) { return ItemStackHelper.removeItem(this.items, i1, i2); } @Override public ItemStack removeItemNoUpdate(int i) { return ItemStackHelper.takeItem(this.items, i); } @Override public void setItem(int index, ItemStack item) { ExampleMod.LOGGER.info("SetItem: "+this); this.items.set(index, item); } @Override public boolean stillValid(PlayerEntity p_70300_1_) { return true; } @Override public void clearContent() { this.items.clear(); } public void startOpen(PlayerEntity p_174889_1_) { this.openCount++; } public void stopOpen(PlayerEntity p_174886_1_) { if (this.openCount > 0) { this.openCount--; } } @Nullable @Override public SUpdateTileEntityPacket getUpdatePacket() { return new SUpdateTileEntityPacket(this.worldPosition, 24, getUpdateTag()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { BlockState state = this.getLevel().getBlockState(this.worldPosition); load(state, pkt.getTag()); } public CompoundNBT getUpdateTag() { return this.saveMetadataAndItems(new CompoundNBT()); } private CompoundNBT saveMetadataAndItems(CompoundNBT p_213983_1_) { super.save(p_213983_1_); ItemStackHelper.saveAllItems(p_213983_1_, this.items, true); return p_213983_1_; } @Override public void handleUpdateTag(BlockState blockState, CompoundNBT tag) { this.load(blockState, tag); } } Could be that the problem?
  4. public void load(BlockState state, CompoundNBT nbt) { super.load(state, nbt); this.items = NonNullList.withSize(10, ItemStack.EMPTY); ItemStackHelper.loadAllItems(nbt, this.items); } public CompoundNBT save(CompoundNBT nbt) { super.save(nbt); ItemStackHelper.saveAllItems(nbt, this.items); return nbt; } @Override public SUpdateTileEntityPacket getUpdatePacket() { return new SUpdateTileEntityPacket(this.worldPosition, 24, getUpdateTag()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { load(this.getBlockState(), pkt.getTag()); } public CompoundNBT getUpdateTag() { return this.saveMetadataAndItems(new CompoundNBT()); } private CompoundNBT saveMetadataAndItems(CompoundNBT p_213983_1_) { super.save(p_213983_1_); ItemStackHelper.saveAllItems(p_213983_1_, this.items, true); return p_213983_1_; } @Override public void handleUpdateTag(BlockState blockState, CompoundNBT tag) { this.load(blockState, tag); } Im kinda new to this. Is there anything else I should override?
  5. Hello there! I am once again asking for your Modding support. So I made a TileEntityRenderer and it all works find. It renders and everything is wonderful. The thing is, in the "render" function when I try to access data from the TileEntity, it is always empty. While debugging I noticed that the instance of my TileEntity is different from the one in the TER. For example: if i get it from the Block or the TileEntity itself : "com.example.examplemod.MyTileEntity@7158bcf2" If I get it from the TER: "com.example.examplemod.MyTileEntity@4251b1ed" @Override public void render(MyTileEntity tileEntity, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer renderTypeBuffer, int light, int overlay) { float item = tileEntity.getItem(); //This always returns "Air" no matter what I do :c this.render(matrixStack, ivertexbuilder, this.lid, this.lock, this.bottom, openness, light, overlay); } Thank you! n.n
  6. Hello there! I'm having some issues using the onBlockActivated method. I cannot find it. It doesnt exist in the super class "Block" nor "AbstractBlock". Im using Minecraft 1.16.5. Is there any Interface i should implement or something? I extended the class ContainerBlock. However, I didnt find this method or similar in any of the related classes. @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { return ActionResultType.PASS; } Thank you! n.n
×
×
  • Create New...

Important Information

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