Skip to content

Commit

Permalink
Merge pull request #278 from jpenilla/be-data
Browse files Browse the repository at this point in the history
Save block entity data to display ItemStacks for laser node GUI
  • Loading branch information
Direwolf20-MC authored Jul 28, 2024
2 parents ec501cb + 3adc4c1 commit 84e3098
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand All @@ -31,6 +32,8 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.network.PacketDistributor;

Expand Down Expand Up @@ -142,8 +145,16 @@ protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
}

protected ItemStack getAdjacentBlock(Direction direction) {
BlockState blockState = container.playerEntity.level().getBlockState(this.container.tile.getBlockPos().relative(direction));
BlockPos blockPos = this.container.tile.getBlockPos().relative(direction);
Level level = this.container.playerEntity.level();
BlockState blockState = level.getBlockState(blockPos);
ItemStack itemStack = blockState.getBlock().asItem().getDefaultInstance();
if (blockState.hasBlockEntity()) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);
if (blockEntity != null) {
blockEntity.saveToItem(itemStack, level.registryAccess());
}
}
return itemStack;
}

Expand Down

0 comments on commit 84e3098

Please sign in to comment.