Skip to content

Commit 33c99da

Browse files
committed
Port barrel -> custom inventory conversion.
1 parent 4ef56f7 commit 33c99da

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/main/java/noobanidus/mods/lootr/command/CommandLootr.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import com.mojang.brigadier.arguments.StringArgumentType;
77
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
88
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
9-
import net.minecraft.block.Block;
10-
import net.minecraft.block.BlockState;
11-
import net.minecraft.block.Blocks;
12-
import net.minecraft.block.ChestBlock;
9+
import net.minecraft.block.*;
1310
import net.minecraft.command.CommandSource;
1411
import net.minecraft.command.Commands;
1512
import net.minecraft.command.ISuggestionProvider;
@@ -19,6 +16,7 @@
1916
import net.minecraft.item.ItemStack;
2017
import net.minecraft.loot.LootTables;
2118
import net.minecraft.state.EnumProperty;
19+
import net.minecraft.tileentity.BarrelTileEntity;
2220
import net.minecraft.tileentity.ChestTileEntity;
2321
import net.minecraft.tileentity.LockableLootTileEntity;
2422
import net.minecraft.tileentity.TileEntity;
@@ -181,17 +179,30 @@ public LiteralArgumentBuilder<CommandSource> builder(LiteralArgumentBuilder<Comm
181179
BlockPos pos = new BlockPos(c.getSource().getPosition());
182180
World world = c.getSource().getLevel();
183181
BlockState state = world.getBlockState(pos);
184-
if (!state.is(Blocks.CHEST)) {
182+
if (!state.is(Blocks.CHEST) && !state.is(Blocks.BARREL)) {
185183
pos = pos.below();
186184
state = world.getBlockState(pos);
187185
}
188-
if (!state.is(Blocks.CHEST)) {
186+
if (!state.is(Blocks.CHEST) && !state.is(Blocks.BARREL)) {
189187
c.getSource().sendSuccess(new StringTextComponent("Please stand on the chest you wish to convert."), false);
190188
} else {
191-
NonNullList<ItemStack> reference = ((ChestTileEntity) Objects.requireNonNull(world.getBlockEntity(pos))).items;
189+
NonNullList<ItemStack> reference;
190+
BlockState newBlock;
191+
if (state.is(Blocks.CHEST)) {
192+
reference = ((ChestTileEntity) Objects.requireNonNull(world.getBlockEntity(pos))).items;
193+
newBlock = ModBlocks.INVENTORY.defaultBlockState().setValue(ChestBlock.FACING, state.getValue(ChestBlock.FACING)).setValue(ChestBlock.WATERLOGGED, state.getValue(ChestBlock.WATERLOGGED));
194+
} else {
195+
reference = ((BarrelTileEntity) Objects.requireNonNull(world.getBlockEntity(pos))).items;
196+
Direction facing = state.getValue(BarrelBlock.FACING);
197+
if (facing == Direction.UP || facing == Direction.DOWN) {
198+
facing = Direction.NORTH;
199+
}
200+
newBlock = ModBlocks.INVENTORY.defaultBlockState().setValue(ChestBlock.FACING, facing);
201+
}
202+
192203
NonNullList<ItemStack> custom = ChestUtil.copyItemList(reference);
193204
world.removeBlockEntity(pos);
194-
world.setBlockAndUpdate(pos, ModBlocks.INVENTORY.defaultBlockState().setValue(ChestBlock.FACING, state.getValue(ChestBlock.FACING)).setValue(ChestBlock.WATERLOGGED, state.getValue(ChestBlock.WATERLOGGED)));
205+
world.setBlockAndUpdate(pos, newBlock);
195206
TileEntity te = world.getBlockEntity(pos);
196207
if (!(te instanceof LootrInventoryTileEntity)) {
197208
c.getSource().sendSuccess(new StringTextComponent("Unable to convert chest, BlockState is not a Lootr Inventory block."), false);

src/main/resources/META-INF/accesstransformer.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ public net.minecraft.server.management.PlayerProfileCache field_152661_c # usern
77
public net.minecraft.world.gen.feature.structure.OceanRuinPieces$Piece field_204040_h # isLarge
88
public net.minecraft.tileentity.LockableLootTileEntity field_184284_m # lootTable
99
public net.minecraft.tileentity.LockableLootTileEntity field_184285_n # lootTableSeed
10-
public net.minecraft.world.chunk.Chunk field_201618_i # pendingBlockEntities
10+
public net.minecraft.world.chunk.Chunk field_201618_i # pendingBlockEntities
11+
public net.minecraft.tileentity.BarrelTileEntity field_213966_a # items

0 commit comments

Comments
 (0)