|
6 | 6 | import com.mojang.brigadier.arguments.StringArgumentType;
|
7 | 7 | import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
8 | 8 | 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.*; |
13 | 10 | import net.minecraft.command.CommandSource;
|
14 | 11 | import net.minecraft.command.Commands;
|
15 | 12 | import net.minecraft.command.ISuggestionProvider;
|
|
19 | 16 | import net.minecraft.item.ItemStack;
|
20 | 17 | import net.minecraft.loot.LootTables;
|
21 | 18 | import net.minecraft.state.EnumProperty;
|
| 19 | +import net.minecraft.tileentity.BarrelTileEntity; |
22 | 20 | import net.minecraft.tileentity.ChestTileEntity;
|
23 | 21 | import net.minecraft.tileentity.LockableLootTileEntity;
|
24 | 22 | import net.minecraft.tileentity.TileEntity;
|
@@ -181,17 +179,30 @@ public LiteralArgumentBuilder<CommandSource> builder(LiteralArgumentBuilder<Comm
|
181 | 179 | BlockPos pos = new BlockPos(c.getSource().getPosition());
|
182 | 180 | World world = c.getSource().getLevel();
|
183 | 181 | BlockState state = world.getBlockState(pos);
|
184 |
| - if (!state.is(Blocks.CHEST)) { |
| 182 | + if (!state.is(Blocks.CHEST) && !state.is(Blocks.BARREL)) { |
185 | 183 | pos = pos.below();
|
186 | 184 | state = world.getBlockState(pos);
|
187 | 185 | }
|
188 |
| - if (!state.is(Blocks.CHEST)) { |
| 186 | + if (!state.is(Blocks.CHEST) && !state.is(Blocks.BARREL)) { |
189 | 187 | c.getSource().sendSuccess(new StringTextComponent("Please stand on the chest you wish to convert."), false);
|
190 | 188 | } 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 | + |
192 | 203 | NonNullList<ItemStack> custom = ChestUtil.copyItemList(reference);
|
193 | 204 | 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); |
195 | 206 | TileEntity te = world.getBlockEntity(pos);
|
196 | 207 | if (!(te instanceof LootrInventoryTileEntity)) {
|
197 | 208 | c.getSource().sendSuccess(new StringTextComponent("Unable to convert chest, BlockState is not a Lootr Inventory block."), false);
|
|
0 commit comments