diff --git a/.gitignore b/.gitignore index f6d5990ae..0185152f6 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,5 @@ forge*changelog.txt /src/main/resources/assets/overdrive_that_matters/models/item/matter_transform_matrix.json /src/main/resources/assets/overdrive_that_matters/models/item/tritanium_ingot.json /src/main/resources/assets/overdrive_that_matters/models/item/tritanium_plate.json +/src/main/resources/assets/overdrive_that_matters/blockstates/cargo_crate.json +/src/main/resources/data/overdrive_that_matters/loot_tables/blocks/cargo_crate.json diff --git a/shapenator.js b/shapenator.js index 4aed446de..bd1736fb1 100644 --- a/shapenator.js +++ b/shapenator.js @@ -384,6 +384,7 @@ const facings = [ // просто дропы блоков { const blocks = [ + 'cargo_crate', 'matter_cable', 'tritanium_block', 'tritanium_striped_block', @@ -417,6 +418,24 @@ const facings = [ } } +// Cargo Crate +{ + const blockstate = { + variants: {} + } + + for (const face of facings) { + for (const open of [true, false]) { + blockstate.variants['facing=' + face.facing + ',open=' + open] = { + model: 'overdrive_that_matters:block/cargo_crate_' + (open ? 'open' : 'closed'), + y: face.y + } + } + } + + fs.writeFileSync(_root + 'blockstates/cargo_crate.json', JSON.stringify(blockstate, null, '\t')) +} + // Обычные блокстейты { const blocks = [ diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index a875a1a3c..334e54166 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -105,6 +105,7 @@ public class Registry { public static final ResourceLocation DRIVE_VIEWER = new ResourceLocation(OverdriveThatMatters.MOD_ID, "drive_viewer"); public static final ResourceLocation BLACK_HOLE = new ResourceLocation(OverdriveThatMatters.MOD_ID, "black_hole"); + public static final ResourceLocation CARGO_CRATE = new ResourceLocation(OverdriveThatMatters.MOD_ID, "cargo_crate"); // building blocks public static final ResourceLocation TRITANIUM_BLOCK = new ResourceLocation(OverdriveThatMatters.MOD_ID, "tritanium_block"); @@ -214,19 +215,20 @@ public class Registry { } public static class Blocks { - public static final Block ANDROID_STATION = new BlockAndroidStation(); - public static final Block BATTERY_BANK = new BlockBatteryBank(); - public static final Block MATTER_DECOMPOSER = new BlockMatterDecomposer(); - public static final Block MATTER_CAPACITOR_BANK = new BlockMatterCapacitorBank(); - public static final Block MATTER_CABLE = new BlockMatterCable(); - public static final Block PATTERN_STORAGE = new BlockPatternStorage(); - public static final Block MATTER_SCANNER = new BlockMatterScanner(); - public static final Block MATTER_PANEL = new BlockMatterPanel(); - public static final Block MATTER_REPLICATOR = new BlockMatterReplicator(); - public static final Block MATTER_BOTTLER = new BlockMatterBottler(); - public static final Block DRIVE_VIEWER = new BlockDriveViewer(); + public static final BlockAndroidStation ANDROID_STATION = new BlockAndroidStation(); + public static final BlockBatteryBank BATTERY_BANK = new BlockBatteryBank(); + public static final BlockMatterDecomposer MATTER_DECOMPOSER = new BlockMatterDecomposer(); + public static final BlockMatterCapacitorBank MATTER_CAPACITOR_BANK = new BlockMatterCapacitorBank(); + public static final BlockMatterCable MATTER_CABLE = new BlockMatterCable(); + public static final BlockPatternStorage PATTERN_STORAGE = new BlockPatternStorage(); + public static final BlockMatterScanner MATTER_SCANNER = new BlockMatterScanner(); + public static final BlockMatterPanel MATTER_PANEL = new BlockMatterPanel(); + public static final BlockMatterReplicator MATTER_REPLICATOR = new BlockMatterReplicator(); + public static final BlockMatterBottler MATTER_BOTTLER = new BlockMatterBottler(); + public static final BlockDriveViewer DRIVE_VIEWER = new BlockDriveViewer(); + public static final BlockCargoCrate CARGO_CRATE = new BlockCargoCrate(); - public static final Block BLACK_HOLE = new BlockBlackHole(); + public static final BlockBlackHole BLACK_HOLE = new BlockBlackHole(); public static final Block[] CRATES = new Block[Registry.CRATES.length]; @@ -276,6 +278,7 @@ public class Registry { MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER); DRIVE_VIEWER.setRegistryName(Names.DRIVE_VIEWER); BLACK_HOLE.setRegistryName(Names.BLACK_HOLE); + CARGO_CRATE.setRegistryName(Names.CARGO_CRATE); TRITANIUM_BLOCK.setRegistryName(Names.TRITANIUM_BLOCK); TRITANIUM_STRIPED_BLOCK.setRegistryName(Names.TRITANIUM_STRIPED_BLOCK); @@ -299,6 +302,7 @@ public class Registry { event.getRegistry().register(TRITANIUM_STRIPED_BLOCK); event.getRegistry().register(CARBON_FIBRE_BLOCK); event.getRegistry().register(BLACK_HOLE); + event.getRegistry().register(CARGO_CRATE); for (var crate : CRATES) { event.getRegistry().register(crate); @@ -320,6 +324,7 @@ public class Registry { public static final Item MATTER_REPLICATOR = new BlockItem(Blocks.MATTER_REPLICATOR, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); public static final Item MATTER_BOTTLER = new BlockItem(Blocks.MATTER_BOTTLER, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); public static final Item DRIVE_VIEWER = new BlockItem(Blocks.DRIVE_VIEWER, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); + public static final Item CARGO_CRATE = new BlockItem(Blocks.CARGO_CRATE, new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); public static final Item TRITANIUM_INGOT = new Item(new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); public static final Item MATTER_IO_PORT = new Item(new Item.Properties().stacksTo(64).tab(OverdriveThatMatters.CREATIVE_TAB)); @@ -387,6 +392,7 @@ public class Registry { MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER); DRIVE_VIEWER.setRegistryName(Names.DRIVE_VIEWER); BLACK_HOLE.setRegistryName(Names.BLACK_HOLE); + CARGO_CRATE.setRegistryName(Names.CARGO_CRATE); TRITANIUM_INGOT.setRegistryName(Names.TRITANIUM_INGOT); MATTER_IO_PORT.setRegistryName(Names.MATTER_IO_PORT); @@ -445,6 +451,7 @@ public class Registry { event.getRegistry().register(MATTER_BOTTLER); event.getRegistry().register(DRIVE_VIEWER); event.getRegistry().register(BLACK_HOLE); + event.getRegistry().register(CARGO_CRATE); event.getRegistry().register(TRITANIUM_INGOT); event.getRegistry().register(MATTER_IO_PORT); @@ -509,6 +516,7 @@ public class Registry { public static final BlockEntityType MATTER_BOTTLER = BlockEntityType.Builder.of(BlockEntityMatterBottler::new, Blocks.MATTER_BOTTLER).build(null); public static final BlockEntityType DRIVE_VIEWER = BlockEntityType.Builder.of(BlockEntityDriveViewer::new, Blocks.DRIVE_VIEWER).build(null); public static final BlockEntityType BLACK_HOLE = BlockEntityType.Builder.of(BlockEntityBlackHole::new, Blocks.BLACK_HOLE).build(null); + public static final BlockEntityType CARGO_CRATE = BlockEntityType.Builder.of(BlockEntityCargoCrate::new, Blocks.CARGO_CRATE).build(null); static { ANDROID_STATION.setRegistryName(Names.ANDROID_STATION); @@ -523,6 +531,7 @@ public class Registry { MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER); DRIVE_VIEWER.setRegistryName(Names.DRIVE_VIEWER); BLACK_HOLE.setRegistryName(Names.BLACK_HOLE); + CARGO_CRATE.setRegistryName(Names.CARGO_CRATE); } @SubscribeEvent @@ -539,6 +548,7 @@ public class Registry { event.getRegistry().register(MATTER_BOTTLER); event.getRegistry().register(DRIVE_VIEWER); event.getRegistry().register(BLACK_HOLE); + event.getRegistry().register(CARGO_CRATE); // OverdriveThatMatters.LOGGER.info("Registered block entities"); } @@ -781,6 +791,7 @@ public class Registry { public static final MenuType MATTER_REPLICATOR = new MenuType<>(MatterReplicatorMenu::new); public static final MenuType MATTER_BOTTLER = new MenuType<>(MatterBottlerMenu::new); public static final MenuType DRIVE_VIEWER = new MenuType<>(DriveViewerMenu::new); + public static final MenuType CARGO_CRATE = new MenuType<>(CargoCrateMenu::new); static { ANDROID_STATION.setRegistryName(Names.ANDROID_STATION); @@ -793,6 +804,7 @@ public class Registry { MATTER_REPLICATOR.setRegistryName(Names.MATTER_REPLICATOR); MATTER_BOTTLER.setRegistryName(Names.MATTER_BOTTLER); DRIVE_VIEWER.setRegistryName(Names.DRIVE_VIEWER); + CARGO_CRATE.setRegistryName(Names.CARGO_CRATE); } @SubscribeEvent @@ -807,6 +819,7 @@ public class Registry { event.getRegistry().register(MATTER_REPLICATOR); event.getRegistry().register(MATTER_BOTTLER); event.getRegistry().register(DRIVE_VIEWER); + event.getRegistry().register(CARGO_CRATE); // OverdriveThatMatters.LOGGER.info("Registered menus"); } @@ -823,6 +836,7 @@ public class Registry { MenuScreens.register(MATTER_REPLICATOR, MatterReplicatorScreen::new); MenuScreens.register(MATTER_BOTTLER, MatterBottlerScreen::new); MenuScreens.register(DRIVE_VIEWER, DriveViewerScreen::new); + MenuScreens.register(CARGO_CRATE, CargoCrateScreen::new); // OverdriveThatMatters.LOGGER.info("Registered screens"); } diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/BlockCargoCrate.java b/src/main/java/ru/dbotthepony/mc/otm/block/BlockCargoCrate.java new file mode 100644 index 000000000..f7a1a9c07 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/block/BlockCargoCrate.java @@ -0,0 +1,52 @@ +package ru.dbotthepony.mc.otm.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.Container; +import net.minecraft.world.Containers; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate; + +import javax.annotation.Nullable; + +public class BlockCargoCrate extends BlockMatteryRotatable implements EntityBlock { + public static final BooleanProperty IS_OPEN = BooleanProperty.create("open"); + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { + return new BlockEntityCargoCrate(blockPos, blockState); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(IS_OPEN); + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + return super.getStateForPlacement(context).setValue(IS_OPEN, false); + } + + @Override + public void onRemove(BlockState old_block_state, Level level, BlockPos block_pos, BlockState new_block_state, boolean p_51542_) { + if (!old_block_state.is(new_block_state.getBlock())) { + BlockEntity blockentity = level.getBlockEntity(block_pos); + + if (blockentity instanceof BlockEntityCargoCrate crate) { + Containers.dropContents(level, block_pos, crate.slots); + level.updateNeighbourForOutputSignal(block_pos, this); + } + + super.onRemove(old_block_state, level, block_pos, new_block_state, p_51542_); + } + } +} diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityCargoCrate.java b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityCargoCrate.java new file mode 100644 index 000000000..7c1432a7d --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityCargoCrate.java @@ -0,0 +1,64 @@ +package ru.dbotthepony.mc.otm.block.entity; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import ru.dbotthepony.mc.otm.Registry; +import ru.dbotthepony.mc.otm.block.BlockCargoCrate; +import ru.dbotthepony.mc.otm.container.MatteryContainer; +import ru.dbotthepony.mc.otm.menu.CargoCrateMenu; + +import javax.annotation.Nullable; + +public class BlockEntityCargoCrate extends BlockEntityMattery { + private static final TranslatableComponent NAME = new TranslatableComponent("block.overdrive_that_matters.cargo_crate"); + public int open_amount = 0; + + public void onPlayerOpen() { + if (open_amount++ == 0 && level != null) { + level.setBlock(getBlockPos(), getBlockState().setValue(BlockCargoCrate.IS_OPEN, true), Block.UPDATE_CLIENTS); + } + } + + public void onPlayerClose() { + if (--open_amount == 0 && level != null) { + level.setBlock(getBlockPos(), getBlockState().setValue(BlockCargoCrate.IS_OPEN, false), Block.UPDATE_CLIENTS); + } + } + + public final MatteryContainer slots = new MatteryContainer(this::setChanged, 9 * 6); + + public BlockEntityCargoCrate(BlockPos p_155229_, BlockState p_155230_) { + super(Registry.BlockEntities.CARGO_CRATE, p_155229_, p_155230_); + } + + @Override + public CompoundTag save(CompoundTag nbt) { + nbt.put("slots", slots.serializeNBT()); + return super.save(nbt); + } + + @Override + public void load(CompoundTag nbt) { + super.load(nbt); + slots.deserializeNBT(nbt.get("slots")); + } + + @Override + protected Component getDefaultDisplayName() { + return NAME; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) { + return new CargoCrateMenu(containerID, inventory, this); + } +} diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/screen/CargoCrateScreen.java b/src/main/java/ru/dbotthepony/mc/otm/client/screen/CargoCrateScreen.java new file mode 100644 index 000000000..769b3afb5 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/client/screen/CargoCrateScreen.java @@ -0,0 +1,30 @@ +package ru.dbotthepony.mc.otm.client.screen; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; +import ru.dbotthepony.mc.otm.client.screen.panels.Dock; +import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel; +import ru.dbotthepony.mc.otm.client.screen.panels.GridPanel; +import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel; +import ru.dbotthepony.mc.otm.menu.CargoCrateMenu; + +import javax.annotation.Nullable; + +public class CargoCrateScreen extends MatteryScreen { + public CargoCrateScreen(CargoCrateMenu menu, Inventory inventory, Component title) { + super(menu, inventory, title); + } + + @Nullable + @Override + protected FramePanel makeMainFrame() { + var frame = new FramePanel(this, null, 0, 0, INVENTORY_FRAME_WIDTH, 22 + 4 + 6 * 18, getTitle()); + + var grid = new GridPanel(this, frame, 8, 18, 9 * 18, 6 * 18, 9, 6); + + for (var slot : menu.crate_slots) + new SlotPanel<>(this, grid, slot); + + return frame; + } +} diff --git a/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.java b/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.java index 2ed5ff386..cb99daf43 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.java +++ b/src/main/java/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.java @@ -115,13 +115,16 @@ public abstract class MatteryScreen extends AbstractConta public FramePanel main_frame; private boolean made_main_frame = false; + public static final int INVENTORY_FRAME_WIDTH = 18 * 9 + 16; + public static final int INVENTORY_FRAME_HEIGHT = 3 * 18 + 18 + 24; + public MatteryScreen(T menu, Inventory inventory, Component title) { super(menu, inventory, title); this.menu = menu; playerInventoryTitle = inventory.getDisplayName(); if (menu.inventory_slots.size() != 0) { - inventory_frame = new FramePanel(this, null, 0, 0, 18 * 9 + 16, 3 * 18 + 18 + 24, inventory.getDisplayName()); + inventory_frame = new FramePanel(this, null, 0, 0, INVENTORY_FRAME_WIDTH, INVENTORY_FRAME_HEIGHT, inventory.getDisplayName()); panels.add(inventory_frame); for (var slot : menu.inventory_slots) { diff --git a/src/main/java/ru/dbotthepony/mc/otm/menu/CargoCrateMenu.java b/src/main/java/ru/dbotthepony/mc/otm/menu/CargoCrateMenu.java new file mode 100644 index 000000000..ead196df6 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/menu/CargoCrateMenu.java @@ -0,0 +1,50 @@ +package ru.dbotthepony.mc.otm.menu; + +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.BlockEntity; +import ru.dbotthepony.mc.otm.Registry; +import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate; +import ru.dbotthepony.mc.otm.menu.slot.MatterySlot; + +public class CargoCrateMenu extends MatteryMenu { + public CargoCrateMenu(int p_38852_, Inventory inventory) { + this(p_38852_, inventory, null); + } + + public final MatterySlot[] crate_slots = new MatterySlot[9 * 6]; + + public CargoCrateMenu(int p_38852_, Inventory inventory, BlockEntityCargoCrate tile) { + super(Registry.Menus.CARGO_CRATE, p_38852_, inventory, tile); + var container = tile != null ? tile.slots : new SimpleContainer(9 * 6); + + for (int i = 0; i < container.getContainerSize(); i++) { + crate_slots[i] = new MatterySlot(container, i); + addSlot(crate_slots[i]); + } + + if (tile != null) + tile.onPlayerOpen(); + + addInventorySlots(); + } + + @Override + public void removed(Player p_38940_) { + super.removed(p_38940_); + + if (tile != null) + ((BlockEntityCargoCrate) tile).onPlayerClose(); + } + + @Override + protected int getWorkingSlotStart() { + return 0; + } + + @Override + protected int getWorkingSlotEnd() { + return 9 * 6 + 1; + } +} diff --git a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json index 659814e75..1fe2f5872 100644 --- a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json +++ b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json @@ -154,7 +154,8 @@ "block.overdrive_that_matters.carbon_fibre_block": "Carbon fibre Block", "block.overdrive_that_matters.tritanium_block": "Tritanium Block", "block.overdrive_that_matters.tritanium_striped_block": "Tritanium Striped Block", - + "block.overdrive_that_matters.cargo_crate": "Cargo Crate", + "item.overdrive_that_matters.pill_android": "Android Pill", "item.overdrive_that_matters.pill_humane": "Humane Pill", diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index a23ca4686..23ab41d33 100644 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -21,6 +21,7 @@ "overdrive_that_matters:crate_green", "overdrive_that_matters:crate_black", "overdrive_that_matters:crate_pink", - "overdrive_that_matters:crate_purple" + "overdrive_that_matters:crate_purple", + "overdrive_that_matters:cargo_crate" ] } \ No newline at end of file