• Posts

    • I want to create a block with one slot that can store items but when I click on it nothing happens Block class: package com.budrunbun.lavalamp.blocks; import com.budrunbun.lavalamp.containers.CheeseGeneratorContainer; import com.budrunbun.lavalamp.tileEntities.CheeseGeneratorTE; import com.budrunbun.lavalamp.tileEntities.ModTileEntities; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.stats.Stats; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import javax.annotation.Nullable; public class CheeseGenerator extends Block { public CheeseGenerator() { super(Block.Properties.create(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(1.0f)); setRegistryName("cheese_generator"); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.FACING); } /* public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) { return Direction.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ())); }*/ @Override public boolean hasTileEntity(BlockState state) { return true; } @Nullable @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return ModTileEntities.CHEESE_GENERATOR_TE.create(); } @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (!worldIn.isRemote()) { return true; } else { INamedContainerProvider iNamedContainerProvider = this.getContainer(state, worldIn, pos); if (iNamedContainerProvider instanceof CheeseGeneratorContainer) { player.openContainer(iNamedContainerProvider); player.addStat(Stats.CUSTOM.get(Stats.OPEN_CHEST)); } } return true; } public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { if (stack.hasDisplayName()) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof CheeseGeneratorTE) { ((CheeseGeneratorTE)tileentity).setCustomName(stack.getDisplayName()); } } } } Tile entity: package com.budrunbun.lavalamp.tileEntities; import com.budrunbun.lavalamp.containers.CheeseGeneratorContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.container.ChestContainer; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.LockableLootTileEntity; import net.minecraft.tileentity.LockableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.ICapabilityProvider; public class CheeseGeneratorTE extends LockableTileEntity implements INamedContainerProvider { private NonNullList<ItemStack> items = NonNullList.withSize(1, ItemStack.EMPTY); public CheeseGeneratorTE() { super(ModTileEntities.CHEESE_GENERATOR_TE); } @Override public int getSizeInventory() { return this.items.size(); } @Override public boolean isEmpty() { for(ItemStack itemstack : this.items) { if (!itemstack.isEmpty()) { return false; } } return true; } @Override public ItemStack getStackInSlot(int index) { return index >= 0 && index < this.items.size() ? this.items.get(index) : ItemStack.EMPTY; } @Override public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.items, index, count); } @Override public ItemStack removeStackFromSlot(int index) { return ItemStackHelper.getAndRemove(this.items, index); } @Override public void setInventorySlotContents(int index, ItemStack stack) { if (index >= 0 && index < this.items.size()) { this.items.set(index, stack); } } @Override public boolean isUsableByPlayer(PlayerEntity player) { if (this.world.getTileEntity(this.pos) != this) { return false; } else { return !(player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) > 64.0D); } } @Override protected Container createMenu(int windowId, PlayerInventory playerInventory) { return new CheeseGeneratorContainer(windowId, playerInventory, this); } @Override public void read(CompoundNBT compound) { super.read(compound); this.loadFromNbt(compound); } @Override public CompoundNBT write(CompoundNBT compound) { super.write(compound); return this.saveToNbt(compound); } @Override protected ITextComponent getDefaultName() { return new TranslationTextComponent("cheese_generator"); } public void loadFromNbt(CompoundNBT compound) { this.items = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); ItemStackHelper.loadAllItems(compound, this.items); } public CompoundNBT saveToNbt(CompoundNBT compound) { ItemStackHelper.saveAllItems(compound, this.items, false); return compound; } @Override public void clear() { this.items.clear(); } } Screen: package com.budrunbun.lavalamp.screens; import com.budrunbun.lavalamp.containers.CheeseGeneratorContainer; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class CheeseGeneratorScreen extends ContainerScreen<CheeseGeneratorContainer> { private static final ResourceLocation GUI = new ResourceLocation("lavalamp", "textures/gui/container/cheese_generator.png"); public CheeseGeneratorScreen(CheeseGeneratorContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); } public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } /** * Draw the foreground layer for the GuiContainer (everything in front of the items) */ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.font.drawString(this.title.getFormattedText(), 8.0F, 6.0F, 4210752); this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 2), 4210752); } /** * Draws the background layer of this container (behind the items). */ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(GUI); int i = (this.width - this.xSize) / 2; int j = (this.height - this.ySize) / 2; blit(i, j, 0, 0, this.xSize, this.ySize, 256, 256); } } Container: package com.budrunbun.lavalamp.containers; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Slot; public class CheeseGeneratorContainer extends Container { private final IInventory inventory; public CheeseGeneratorContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { super(ModContainers.CHEESE_GENERATOR_CONTAINER, windowId); this.inventory = inventory; assertInventorySize(inventory, 1); this.addSlot(new Slot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18)); int leftCol = (184 - 162) / 2 + 1; for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) { for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) { this.addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, 184 - (4 - playerInvRow) * 18 - 10)); } } for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) { this.addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, 184 - 24)); } } @Override public boolean canInteractWith(PlayerEntity playerIn) { return this.inventory.isUsableByPlayer(playerIn); } }  
    • If my understanding is correct, .executes() needs to put inside the bracket of the .then (all "connected" action needs to do that)which should looks like this root.then(Commands.literal("edit_a_float") .then(Commands.argument("float", FloatArgumentType.floatArg()) -> removed two brackets here .executes(source -> { return editPower(source.getSource(), source.getSource().asPlayer(), FloatArgumentType.getFloat(source, "float")); }))); -> added two brackets here  
    • I keep getting this error when I try to load up the game: "mod_name (mod_ID) has failed to load correctly null" I looked through the latest.log and seen something to do with the specific line of code with "RegistryHandler.init()"on it, so I went to the file that it's in and everything is fine. Even Inspect code doesn't pick up any errors.   FYI I'm using IntelliJ IDEA. latest.log
    • I will make sure to include this as a note in my explanation. Congrats on getting it fixed.
    • I made a resource pack for 1.16 but when I put it in the folder it doesnt show up in my game. Can someone help please?    I got it to work now so i dont need help
  • Topics

  • Who's Online (See full list)