Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Daru

Members
  • Joined

  • Last visited

  1. I want to create more Blockstates for Campfire blocks and then redefine how to use them to interact with Campfire. So I decided to create a new customized Campfire class that extends the Campfire Block. And we're going to replace this new Campfire Block with the original Campfire Block. But the problem is that I got an error when I tried to register a new block as "minecraft:campfire". Invalid vanilla replacement. Here's my question. Is there a way to replace vanilla blocks with custom blocks with additional properties?
  2. Daru changed their profile photo
  3. @warjortOh, I see! It's finally working fine!! Thx for the help.XD You're a genius.
  4. I created Generator BlockEntity with Screen. And I made an interactive power button on the generator screen and the button works fine. However, the problem arises here, although the power value of some entity( ex: @23343) changes when the power is turned on or off, but the power value of the block( ex: @23434) does not actually change. So can I ask for your help? My Code is Here! Block Entity : public class GeneratorEntity extends BlockEntity implements MenuProvider { private boolean power = false; private int progress = 0; public GeneratorEntity(BlockPos pos, BlockState state) { super(ModBlockEntities.SMALL_GENERATOR.get(), pos, state); } @Nullable @Override public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { return new SmallGeneratorMenu(id,inventory,this,this.data); } @Override protected void saveAdditional(CompoundTag nbt) { nbt.putBoolean("IsPowered",this.power); super.saveAdditional(nbt); } @Override public void load(CompoundTag nbt) { super.load(nbt); power = nbt.getBoolean("IsPowered"); } public static void tick(Level level, BlockPos pos, BlockState state, GeneratorEntity pEntity) { if (level.isClientSide()) { return; } if (pEntity.getPower()==true) { if (hasEnough(pEntity)) { pEntity.progress++; setChanged(level, pos, state); } else { pEntity.resetProgress(); setChanged(level, pos, state); } } else{ pEntity.resetProgress(); setChanged(level, pos, state); } } private void resetProgress() { this.progress = 0; } public boolean getPower() { return power; } public void ChangePower() { this.power = !this.power; setChanged(); ModMessages.sendToClients(new GeneratorPowerSync2CPacket(this.power, this.getBlockPos())); } public boolean setPower(GeneratorEntity pEntity, boolean power){ if (power) { pEntity.power = true; } else { pEntity.power = false; } return power; } } Screen: public class SmallGeneratorScreen extends AbstractContainerScreen<SmallGeneratorMenu> { private static final ResourceLocation TEXTURE = new ResourceLocation(Generator.MOD_ID,"textures/gui/small_generator_gui.png"); private static final ResourceLocation BUTTON = new ResourceLocation(Generator.MOD_ID,"textures/gui/button.png"); private static final ResourceLocation BUTTON_ON = new ResourceLocation(Generator.MOD_ID,"textures/gui/button_on.png"); public SmallGeneratorScreen(SmallGeneratorMenu pMenu, Inventory pPlayerInventory, Component component) { super(pMenu, pPlayerInventory, component); } private ImageButton button = new ImageButton(0,0,16,16,0,0,16,BUTTON,16,32,e -> { if(menu.blockEntity.getPower()){ menu.blockEntity.ChangePower(); } else{ menu.blockEntity.ChangePower(); } }); private ImageButton button_on = new ImageButton(0,0,16,16,0,0,16,BUTTON_ON,16,32,e -> { if(menu.blockEntity.getPower()){ menu.ChangePower(); } else{ menu.ChangePower(); } }); @Override protected void init() { super.init(); this.addRenderableWidget(button); this.addRenderableWidget(button_on); button_on.visible = true; button_on.active = true; button.visible = false; button.active = false; } @Override protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F,1.0F,1.0F,1.0F); RenderSystem.setShaderTexture(0,TEXTURE); int x = (width-imageWidth)/2; int y = (height-imageHeight)/2; this.blit(pPoseStack,x,y,0,0,imageWidth,imageHeight); renderEnergy(pPoseStack,x,y); renderButton(pPoseStack,x,y); renderProgressArrow(pPoseStack,x,y); } private void renderButton(PoseStack pPoseStack, int x, int y) { button.setPosition(x+44,y+50); button_on.setPosition(x+44,y+50); if(menu.blockEntity.getPower()){ button_on.visible = false; button_on.active = false; button.visible = true; button.active = true; } else{ button_on.visible = true; button_on.active = true; button.visible = false; button.active = false; } } } Packet: package com.test.Generator.networking.packet; import com.test.Generator.block.entity.GeneratorEntity; import com.test.Generator.screen.SmallGeneratorMenu; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class GeneratorPowerSync2CPacket { private final boolean power; private final BlockPos pos; public GeneratorPowerSync2CPacket (boolean energy, BlockPos pos) { this.power = energy; this.pos = pos; } public GeneratorPowerSync2CPacket (FriendlyByteBuf buf) { this.power = buf.readBoolean(); this.pos = buf.readBlockPos(); } public void toBytes(FriendlyByteBuf buf) { buf.writeBoolean(power); buf.writeBlockPos(pos); } public boolean handle(Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { if(Minecraft.getInstance().level.getBlockEntity(pos) instanceof GeneratorEntity blockEntity) { blockEntity.setPower(blockEntity,power); if(Minecraft.getInstance().player.containerMenu instanceof SmallGeneratorMenu menu && menu.getBlockEntity().getBlockPos().equals(pos)) { blockEntity.setPower(blockEntity,power); } } }); return true; } } Thank you for your help

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.