package com.thebrokenrail.twine.util.boat; import com.google.common.collect.Lists; import com.thebrokenrail.twine.Twine; import net.minecraft.block.Blocks; import net.minecraft.block.EnderChestBlock; import net.minecraft.block.ShulkerBoxBlock; import net.minecraft.block.entity.BarrelBlockEntity; import net.minecraft.block.entity.ChestBlockEntity; import net.minecraft.block.entity.ShulkerBoxBlockEntity; import net.minecraft.item.ItemStack; import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.ShulkerBoxScreenHandler; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; import java.util.List; import java.util.function.Function; public class BoatChestModes { public static final BoatChestMode NONE = new BoatChestMode(Blocks.AIR, null, null, null, null, null); static void register() { new BoatChestMode(Blocks.ENDER_CHEST, (i, playerInventory, playerEntity, boat, inventoryWrapper) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, inventoryWrapper.apply(playerEntity.getEnderChestInventory())), stack -> EnderChestBlock.CONTAINER_NAME, player -> Twine.ENDER_CHEST_BOAT_CRITERION.trigger(player), SoundEvents.BLOCK_ENDER_CHEST_OPEN, SoundEvents.BLOCK_ENDER_CHEST_CLOSE); BoatChestMode.BoatScreenHandlerFactory chestScreenHandler = (i, playerInventory, playerEntity, boat, inventoryWrapper) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, boat.getChestInventory()); ChestBlockEntity chest = new ChestBlockEntity(); Function chestScreenHandlerName = stack -> stack.hasCustomName() ? stack.getName() : chest.getName(); new BoatChestMode(Blocks.CHEST, true, false, 27, chestScreenHandler, chestScreenHandlerName, player -> Twine.CHEST_BOAT_CRITERION.trigger(player), SoundEvents.BLOCK_CHEST_OPEN, SoundEvents.BLOCK_CHEST_CLOSE); new BoatChestMode(Blocks.TRAPPED_CHEST, true, false, 27, chestScreenHandler, chestScreenHandlerName, player -> Twine.CHEST_BOAT_CRITERION.trigger(player), SoundEvents.BLOCK_CHEST_OPEN, SoundEvents.BLOCK_CHEST_CLOSE); BarrelBlockEntity barrel = new BarrelBlockEntity(); Function barrelScreenHandlerName = stack -> stack.hasCustomName() ? stack.getName() : barrel.getName(); new BoatChestMode(Blocks.BARREL, true, false, 27, chestScreenHandler, barrelScreenHandlerName, player -> Twine.BARREL_BOAT_CRITERION.trigger(player), SoundEvents.BLOCK_BARREL_OPEN, SoundEvents.BLOCK_BARREL_CLOSE); ShulkerBoxBlockEntity shulker = new ShulkerBoxBlockEntity(); List colors = Lists.asList(null, DyeColor.values()); for (DyeColor value : colors) { new BoatChestMode(ShulkerBoxBlock.get(value), true, true, 27, (i, playerInventory, playerEntity, boat, inventoryWrapper) -> new ShulkerBoxScreenHandler(i, playerInventory, boat.getChestInventory()), stack -> stack.hasCustomName() ? stack.getName() : shulker.getName(), player -> Twine.SHULKER_BOX_BOAT_CRITERION.trigger(player), SoundEvents.BLOCK_SHULKER_BOX_OPEN, SoundEvents.BLOCK_SHULKER_BOX_CLOSE); } } }