From 25309e40b40c39d669e7d6dea8061d88e5e83e96 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 8 Aug 2019 19:31:46 +0200 Subject: [PATCH 1/2] Refactor Packet registering --- .../java/com/simibubi/create/AllPackets.java | 63 ++++++++++++++----- .../create/foundation/packet/NbtPacket.java | 6 +- .../foundation/packet/SimplePacketBase.java | 13 ++++ .../BuilderGunBeamPacket.java | 5 +- .../packet/ConfigureSchematicannonPacket.java | 5 +- .../packet/SchematicPlacePacket.java | 5 +- .../packet/SchematicUploadPacket.java | 5 +- .../symmetry/SymmetryEffectPacket.java | 6 +- 8 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/packet/SimplePacketBase.java diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index 0d8308eb0..e2f7f9e64 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -1,41 +1,72 @@ package com.simibubi.create; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Supplier; + import com.simibubi.create.foundation.packet.NbtPacket; +import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunBeamPacket; import com.simibubi.create.modules.schematics.packet.ConfigureSchematicannonPacket; import com.simibubi.create.modules.schematics.packet.SchematicPlacePacket; import com.simibubi.create.modules.schematics.packet.SchematicUploadPacket; import com.simibubi.create.modules.symmetry.SymmetryEffectPacket; +import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.network.NetworkEvent.Context; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; -public class AllPackets { +public enum AllPackets { + + // Client to Server + NBT(NbtPacket.class, NbtPacket::new), + CONFIGURE_SCHEMATICANNON(ConfigureSchematicannonPacket.class, ConfigureSchematicannonPacket::new), + PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new), + UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new), + + // Server to Client + SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new), + BEAM_EFFECT(BuilderGunBeamPacket.class, BuilderGunBeamPacket::new), + + ; public static final ResourceLocation CHANNEL_NAME = new ResourceLocation(Create.ID, "network"); public static final String NETWORK_VERSION = new ResourceLocation(Create.ID, "1").toString(); public static SimpleChannel channel; - public static void registerPackets() { - int i = 0; + private LoadedPacket packet; + private AllPackets(Class type, Function factory) { + packet = new LoadedPacket<>(type, factory); + } + + public static void registerPackets() { channel = NetworkRegistry.ChannelBuilder.named(CHANNEL_NAME).serverAcceptedVersions(s -> true) .clientAcceptedVersions(s -> true).networkProtocolVersion(() -> NETWORK_VERSION).simpleChannel(); - - channel.messageBuilder(NbtPacket.class, i++).decoder(NbtPacket::new).encoder(NbtPacket::toBytes) - .consumer(NbtPacket::handle).add(); - channel.messageBuilder(SchematicPlacePacket.class, i++).decoder(SchematicPlacePacket::new) - .encoder(SchematicPlacePacket::toBytes).consumer(SchematicPlacePacket::handle).add(); - channel.messageBuilder(ConfigureSchematicannonPacket.class, i++).decoder(ConfigureSchematicannonPacket::new) - .encoder(ConfigureSchematicannonPacket::toBytes).consumer(ConfigureSchematicannonPacket::handle).add(); - channel.messageBuilder(SchematicUploadPacket.class, i++).decoder(SchematicUploadPacket::new) - .encoder(SchematicUploadPacket::toBytes).consumer(SchematicUploadPacket::handle).add(); - channel.messageBuilder(SymmetryEffectPacket.class, i++).decoder(SymmetryEffectPacket::new) - .encoder(SymmetryEffectPacket::toBytes).consumer(SymmetryEffectPacket::handle).add(); - channel.messageBuilder(BuilderGunBeamPacket.class, i++).decoder(BuilderGunBeamPacket::new) - .encoder(BuilderGunBeamPacket::toBytes).consumer(BuilderGunBeamPacket::handle).add(); + for (AllPackets packet : values()) + packet.packet.register(); } + private static class LoadedPacket { + private static int index = 0; + BiConsumer encoder; + Function decoder; + BiConsumer> handler; + Class type; + + private LoadedPacket(Class type, Function factory) { + encoder = T::write; + decoder = factory; + handler = T::handle; + this.type = type; + } + + private void register() { + channel.messageBuilder(type, index++).encoder(encoder).decoder(decoder).consumer(handler).add(); + } + } + } diff --git a/src/main/java/com/simibubi/create/foundation/packet/NbtPacket.java b/src/main/java/com/simibubi/create/foundation/packet/NbtPacket.java index 3a313975b..26875bc49 100644 --- a/src/main/java/com/simibubi/create/foundation/packet/NbtPacket.java +++ b/src/main/java/com/simibubi/create/foundation/packet/NbtPacket.java @@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class NbtPacket { +public class NbtPacket extends SimplePacketBase { public ItemStack stack; public int slot; @@ -25,8 +25,8 @@ public class NbtPacket { stack = buffer.readItemStack(); slot = buffer.readInt(); } - - public void toBytes(PacketBuffer buffer) { + + public void write(PacketBuffer buffer) { buffer.writeItemStack(stack); buffer.writeInt(slot); } diff --git a/src/main/java/com/simibubi/create/foundation/packet/SimplePacketBase.java b/src/main/java/com/simibubi/create/foundation/packet/SimplePacketBase.java new file mode 100644 index 000000000..03d6cc064 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/packet/SimplePacketBase.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.packet; + +import java.util.function.Supplier; + +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fml.network.NetworkEvent.Context; + +public abstract class SimplePacketBase { + + public abstract void write(PacketBuffer buffer); + public abstract void handle(Supplier context); + +} diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java index 375c21131..6615e77d4 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunBeamPacket.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.curiosities.placementHandgun; import java.util.function.Supplier; +import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunHandler.LaserBeam; import net.minecraft.client.Minecraft; @@ -13,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class BuilderGunBeamPacket { +public class BuilderGunBeamPacket extends SimplePacketBase { public Vec3d start; public Vec3d target; @@ -34,7 +35,7 @@ public class BuilderGunBeamPacket { self = buffer.readBoolean(); } - public void toBytes(PacketBuffer buffer) { + public void write(PacketBuffer buffer) { buffer.writeDouble(start.x); buffer.writeDouble(start.y); buffer.writeDouble(start.z); diff --git a/src/main/java/com/simibubi/create/modules/schematics/packet/ConfigureSchematicannonPacket.java b/src/main/java/com/simibubi/create/modules/schematics/packet/ConfigureSchematicannonPacket.java index 5423905b4..bbe111009 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/packet/ConfigureSchematicannonPacket.java +++ b/src/main/java/com/simibubi/create/modules/schematics/packet/ConfigureSchematicannonPacket.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.schematics.packet; import java.util.function.Supplier; +import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.schematics.block.SchematicannonTileEntity; import com.simibubi.create.modules.schematics.block.SchematicannonTileEntity.State; @@ -12,7 +13,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class ConfigureSchematicannonPacket { +public class ConfigureSchematicannonPacket extends SimplePacketBase { public static enum Option { DONT_REPLACE, REPLACE_SOLID, REPLACE_ANY, REPLACE_EMPTY, SKIP_MISSING, SKIP_TILES, PLAY, PAUSE, STOP; @@ -39,7 +40,7 @@ public class ConfigureSchematicannonPacket { set = buffer.readBoolean(); } - public void toBytes(PacketBuffer buffer) { + public void write(PacketBuffer buffer) { buffer.writeBlockPos(pos); buffer.writeInt(option.ordinal()); buffer.writeBoolean(set); diff --git a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicPlacePacket.java b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicPlacePacket.java index ec79bcbc9..420b2e422 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicPlacePacket.java +++ b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicPlacePacket.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.schematics.packet; import java.util.function.Supplier; +import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.schematics.item.BlueprintItem; import net.minecraft.entity.player.ServerPlayerEntity; @@ -11,7 +12,7 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.world.gen.feature.template.Template; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class SchematicPlacePacket { +public class SchematicPlacePacket extends SimplePacketBase { public ItemStack stack; @@ -23,7 +24,7 @@ public class SchematicPlacePacket { stack = buffer.readItemStack(); } - public void toBytes(PacketBuffer buffer) { + public void write(PacketBuffer buffer) { buffer.writeItemStack(stack); } diff --git a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java index 5044484de..4c8f800b1 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java +++ b/src/main/java/com/simibubi/create/modules/schematics/packet/SchematicUploadPacket.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.schematics.packet; import java.util.function.Supplier; import com.simibubi.create.Create; +import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.foundation.type.DimensionPos; import com.simibubi.create.modules.schematics.block.SchematicTableContainer; @@ -11,7 +12,7 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class SchematicUploadPacket { +public class SchematicUploadPacket extends SimplePacketBase { public static final int BEGIN = 0; public static final int WRITE = 1; @@ -53,7 +54,7 @@ public class SchematicUploadPacket { data = buffer.readByteArray(); } - public void toBytes(PacketBuffer buffer) { + public void write(PacketBuffer buffer) { buffer.writeInt(code); buffer.writeString(schematic); diff --git a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryEffectPacket.java b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryEffectPacket.java index 3dab4f809..a74e89d61 100644 --- a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryEffectPacket.java +++ b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryEffectPacket.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; +import com.simibubi.create.foundation.packet.SimplePacketBase; + import net.minecraft.client.Minecraft; import net.minecraft.network.PacketBuffer; import net.minecraft.util.math.BlockPos; @@ -12,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.NetworkEvent.Context; -public class SymmetryEffectPacket { +public class SymmetryEffectPacket extends SimplePacketBase { private BlockPos mirror; private List positions; @@ -31,7 +33,7 @@ public class SymmetryEffectPacket { } } - public void toBytes(PacketBuffer buffer) { + public void write(PacketBuffer buffer) { buffer.writeBlockPos(mirror); buffer.writeInt(positions.size()); for (BlockPos blockPos : positions) { From 8ac10da27658112205a0444b6368b15f8eb82cdb Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 8 Aug 2019 23:10:01 +0200 Subject: [PATCH 2/2] Shopping with Mike part 1 - Added Shelf Block, Tile Entity, Container, Screen, Model --- .../java/com/simibubi/create/AllBlocks.java | 7 +- .../com/simibubi/create/AllContainers.java | 5 + .../java/com/simibubi/create/AllItems.java | 33 +++++-- .../com/simibubi/create/AllTileEntities.java | 3 + .../placementHandgun/BuilderGunItem.java | 3 +- .../modules/shopping/ShopShelfBlock.java | 99 +++++++++++++++++++ .../modules/shopping/ShopShelfContainer.java | 25 +++++ .../modules/shopping/ShopShelfScreen.java | 19 ++++ .../modules/shopping/ShopShelfTileEntity.java | 62 ++++++++++++ .../modules/symmetry/SymmetryWandItem.java | 3 +- .../assets/create/blockstates/shop_shelf.json | 12 +++ .../resources/assets/create/lang/en_us.json | 1 + .../create/models/block/shop_shelf.json | 91 +++++++++++++++++ .../assets/create/models/item/shop_shelf.json | 3 + 14 files changed, 354 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java create mode 100644 src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java create mode 100644 src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java create mode 100644 src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java create mode 100644 src/main/resources/assets/create/blockstates/shop_shelf.json create mode 100644 src/main/resources/assets/create/models/block/shop_shelf.json create mode 100644 src/main/resources/assets/create/models/item/shop_shelf.json diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 10c5a8176..f60c2f3b6 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -5,6 +5,7 @@ import com.simibubi.create.foundation.block.RenderUtilityBlock; import com.simibubi.create.modules.schematics.block.CreativeCrateBlock; import com.simibubi.create.modules.schematics.block.SchematicTableBlock; import com.simibubi.create.modules.schematics.block.SchematicannonBlock; +import com.simibubi.create.modules.shopping.ShopShelfBlock; import com.simibubi.create.modules.symmetry.block.CrossPlaneSymmetryBlock; import com.simibubi.create.modules.symmetry.block.PlaneSymmetryBlock; import com.simibubi.create.modules.symmetry.block.TriplePlaneSymmetryBlock; @@ -26,7 +27,11 @@ public enum AllBlocks { SYMMETRY_PLANE(new PlaneSymmetryBlock()), SYMMETRY_CROSSPLANE(new CrossPlaneSymmetryBlock()), - SYMMETRY_TRIPLEPLANE(new TriplePlaneSymmetryBlock()); + SYMMETRY_TRIPLEPLANE(new TriplePlaneSymmetryBlock()), + + SHOP_SHELF(new ShopShelfBlock()), + + ; public Block block; diff --git a/src/main/java/com/simibubi/create/AllContainers.java b/src/main/java/com/simibubi/create/AllContainers.java index 6c78fc068..2cbb79c46 100644 --- a/src/main/java/com/simibubi/create/AllContainers.java +++ b/src/main/java/com/simibubi/create/AllContainers.java @@ -4,6 +4,8 @@ import com.simibubi.create.modules.schematics.block.SchematicTableContainer; import com.simibubi.create.modules.schematics.block.SchematicTableScreen; import com.simibubi.create.modules.schematics.block.SchematicannonContainer; import com.simibubi.create.modules.schematics.block.SchematicannonScreen; +import com.simibubi.create.modules.shopping.ShopShelfContainer; +import com.simibubi.create.modules.shopping.ShopShelfScreen; import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.ScreenManager; @@ -27,6 +29,8 @@ public enum AllContainers { SchematicTable(SchematicTableContainer::new), Schematicannon(SchematicannonContainer::new), + ShopShelf(ShopShelfContainer::new), + ; public ContainerType type; @@ -50,6 +54,7 @@ public enum AllContainers { public static void registerScreenFactories() { bind(SchematicTable, SchematicTableScreen::new); bind(Schematicannon, SchematicannonScreen::new); + bind(ShopShelf, ShopShelfScreen::new); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 5cfc0cbc5..d7041f7e0 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -29,20 +29,25 @@ import net.minecraftforge.registries.IForgeRegistry; public enum AllItems { SYMMETRY_WAND(new SymmetryWandItem( - standardProperties().rarity(Rarity.UNCOMMON).setTEISR(() -> () -> withSpecialRenderer("wand")))), - PLACEMENT_HANDGUN(new BuilderGunItem( - new Properties().rarity(Rarity.UNCOMMON).setTEISR(() -> () -> withSpecialRenderer("gun")))), + standardProperties().setTEISR(() -> () -> renderUsing(AllItemRenderers.SYMMETRY_WAND)))), + + PLACEMENT_HANDGUN( + new BuilderGunItem(new Properties().setTEISR(() -> () -> renderUsing(AllItemRenderers.BUILDER_GUN)))), - ANDESITE_ALLOY_CUBE(new Item(standardProperties())), BLAZE_BRASS_CUBE(new Item(standardProperties())), + ANDESITE_ALLOY_CUBE(new Item(standardProperties())), + BLAZE_BRASS_CUBE(new Item(standardProperties())), CHORUS_CHROME_CUBE(new Item(standardProperties().rarity(Rarity.UNCOMMON))), TREE_FERTILIZER(new TreeFertilizerItem(standardProperties())), + EMPTY_BLUEPRINT(new Item(standardProperties().maxStackSize(1))), BLUEPRINT_AND_QUILL(new BlueprintAndQuillItem(standardProperties().maxStackSize(1))), BLUEPRINT(new BlueprintItem(standardProperties())), - + ; + // Common + public Item item; private AllItems(Item item) { @@ -68,13 +73,23 @@ public enum AllItems { return stack.getItem() == item; } + // Client + + private enum AllItemRenderers { + SYMMETRY_WAND, BUILDER_GUN,; + } + @OnlyIn(Dist.CLIENT) - public static ItemStackTileEntityRenderer withSpecialRenderer(String renderer) { - if ("wand".equals(renderer)) + public static ItemStackTileEntityRenderer renderUsing(AllItemRenderers renderer) { + switch (renderer) { + + case SYMMETRY_WAND: return new SymmetryWandItemRenderer(); - if ("gun".equals(renderer)) + case BUILDER_GUN: return new BuilderGunItemRenderer(); - return null; + default: + return null; + } } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index a8e9ac26d..bd3d43675 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -5,6 +5,7 @@ import java.util.function.Supplier; import com.simibubi.create.modules.schematics.block.SchematicTableTileEntity; import com.simibubi.create.modules.schematics.block.SchematicannonRenderer; import com.simibubi.create.modules.schematics.block.SchematicannonTileEntity; +import com.simibubi.create.modules.shopping.ShopShelfTileEntity; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.tileentity.TileEntity; @@ -21,6 +22,8 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @Mod.EventBusSubscriber(bus = Bus.MOD) public enum AllTileEntities { + ShopShelfTileEntity(ShopShelfTileEntity::new, AllBlocks.SHOP_SHELF), + Schematicannon(SchematicannonTileEntity::new, AllBlocks.SCHEMATICANNON), SchematicTable(SchematicTableTileEntity::new, AllBlocks.SCHEMATIC_TABLE); diff --git a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java index b83f3560e..81f54b67a 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/placementHandgun/BuilderGunItem.java @@ -28,6 +28,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; +import net.minecraft.item.Rarity; import net.minecraft.item.UseAction; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; @@ -70,7 +71,7 @@ public class BuilderGunItem extends Item { } public BuilderGunItem(Properties properties) { - super(properties.maxStackSize(1)); + super(properties.maxStackSize(1).rarity(Rarity.UNCOMMON)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java new file mode 100644 index 000000000..485fb8640 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfBlock.java @@ -0,0 +1,99 @@ +package com.simibubi.create.modules.shopping; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.HorizontalBlock; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemStack; +import net.minecraft.state.StateContainer.Builder; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; +import net.minecraftforge.fml.network.NetworkHooks; + +public class ShopShelfBlock extends HorizontalBlock { + + public static final VoxelShape TOP_SHAPE = makeCuboidShape(0, 14, 0, 16, 16, 16); + + public static final VoxelShape BODY_SOUTH_SHAPE = makeCuboidShape(0, 0, 0, 16, 14, 14); + public static final VoxelShape BODY_NORTH_SHAPE = makeCuboidShape(0, 0, 2, 16, 14, 16); + public static final VoxelShape BODY_EAST_SHAPE = makeCuboidShape(0, 0, 0, 14, 14, 16); + public static final VoxelShape BODY_WEST_SHAPE = makeCuboidShape(2, 0, 0, 16, 14, 16); + + public ShopShelfBlock() { + super(Properties.from(Blocks.SPRUCE_PLANKS)); + } + + @Override + public boolean hasTileEntity(BlockState state) { + return true; + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { + return new ShopShelfTileEntity(); + } + + @Override + public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); + te.setOwner(placer.getUniqueID()); + worldIn.notifyBlockUpdate(pos, state, state, 2); + } + + @Override + public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, + BlockRayTraceResult hit) { + ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); + if (te == null) + return false; + if (!worldIn.isRemote) + NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer); + return true; + } + + @Override + protected void fillStateContainer(Builder builder) { + builder.add(HORIZONTAL_FACING); + super.fillStateContainer(builder); + } + + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + return getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + VoxelShape body = VoxelShapes.empty(); + switch (state.get(HORIZONTAL_FACING)) { + case EAST: + body = BODY_EAST_SHAPE; + break; + case NORTH: + body = BODY_NORTH_SHAPE; + break; + case SOUTH: + body = BODY_SOUTH_SHAPE; + break; + case WEST: + body = BODY_WEST_SHAPE; + break; + default: + break; + } + + return VoxelShapes.or(TOP_SHAPE, body); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java new file mode 100644 index 000000000..5f4619cbb --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfContainer.java @@ -0,0 +1,25 @@ +package com.simibubi.create.modules.shopping; + +import com.simibubi.create.AllContainers; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.network.PacketBuffer; + +public class ShopShelfContainer extends Container { + + public ShopShelfContainer(int id, PlayerInventory inv, ShopShelfTileEntity te) { + super(AllContainers.ShopShelf.type, id); + } + + public ShopShelfContainer(int id, PlayerInventory inv, PacketBuffer extraData) { + super(AllContainers.ShopShelf.type, id); + } + + @Override + public boolean canInteractWith(PlayerEntity playerIn) { + return true; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java new file mode 100644 index 000000000..58b92b31a --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfScreen.java @@ -0,0 +1,19 @@ +package com.simibubi.create.modules.shopping; + +import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; + +public class ShopShelfScreen extends AbstractSimiContainerScreen { + + public ShopShelfScreen(ShopShelfContainer container, PlayerInventory inv, ITextComponent title) { + super(container, inv, title); + } + + @Override + protected void renderWindow(int mouseX, int mouseY, float partialTicks) { + renderTooltip("Hi", mouseX, mouseY); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java new file mode 100644 index 000000000..21f8cf322 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/shopping/ShopShelfTileEntity.java @@ -0,0 +1,62 @@ +package com.simibubi.create.modules.shopping; + +import java.util.UUID; + +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.foundation.block.SyncedTileEntity; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; + +public class ShopShelfTileEntity extends SyncedTileEntity implements INamedContainerProvider { + + private UUID owner; + + public ShopShelfTileEntity() { + super(AllTileEntities.ShopShelfTileEntity.type); + } + + @Override + public void read(CompoundNBT compound) { + if (compound.contains("Owner")) + setOwner(NBTUtil.readUniqueId(compound.getCompound("Owner"))); + super.read(compound); + } + + @Override + public CompoundNBT write(CompoundNBT compound) { + if (getOwner() != null) + compound.put("Owner", NBTUtil.writeUniqueId(getOwner())); + return super.write(compound); + } + + public UUID getOwner() { + return owner; + } + + public void setOwner(UUID owner) { + this.owner = owner; + } + + public void sendToContainer(PacketBuffer buffer) { + buffer.writeUniqueId(getOwner()); + } + + @Override + public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { + return new ShopShelfContainer(id, inventory, this); + } + + @Override + public ITextComponent getDisplayName() { + return new StringTextComponent(getType().getRegistryName().toString()); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java index 996f1abbf..0d75bc3d3 100644 --- a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java +++ b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java @@ -23,6 +23,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; +import net.minecraft.item.Rarity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; @@ -47,7 +48,7 @@ public class SymmetryWandItem extends Item { private static final String $ENABLE = "enable"; public SymmetryWandItem(Properties properties) { - super(properties.maxStackSize(1)); + super(properties.maxStackSize(1).rarity(Rarity.UNCOMMON)); } @Override diff --git a/src/main/resources/assets/create/blockstates/shop_shelf.json b/src/main/resources/assets/create/blockstates/shop_shelf.json new file mode 100644 index 000000000..3a72db05f --- /dev/null +++ b/src/main/resources/assets/create/blockstates/shop_shelf.json @@ -0,0 +1,12 @@ +{ + "forgemarker": 1, + "defaults": { + "model": "create:block/shop_shelf" + }, + "variants": { + "facing=north": { "model": "create:block/shop_shelf", "y": 180 }, + "facing=south": { "model": "create:block/shop_shelf" }, + "facing=east": { "model": "create:block/shop_shelf", "y": 270 }, + "facing=west": { "model": "create:block/shop_shelf", "y": 90 } + } +} diff --git a/src/main/resources/assets/create/lang/en_us.json b/src/main/resources/assets/create/lang/en_us.json index 30947af32..3dbd6d626 100644 --- a/src/main/resources/assets/create/lang/en_us.json +++ b/src/main/resources/assets/create/lang/en_us.json @@ -11,5 +11,6 @@ "block.create.schematicannon": "Schematicannon", "block.create.schematic_table": "Schematic Table", "block.create.creative_crate": "Schematicannon Creatifier", + "block.create.shop_shelf": "Shelf", "itemGroup.create": "Create" } diff --git a/src/main/resources/assets/create/models/block/shop_shelf.json b/src/main/resources/assets/create/models/block/shop_shelf.json new file mode 100644 index 000000000..c330f4852 --- /dev/null +++ b/src/main/resources/assets/create/models/block/shop_shelf.json @@ -0,0 +1,91 @@ +{ + "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)", + "parent": "block/cube", + "textures": { + "particle": "block/stripped_spruce_log", + "0": "block/stripped_spruce_log_top", + "1": "block/stripped_spruce_log", + "2": "block/dark_oak_planks", + "3": "block/spruce_planks", + "4": "block/andesite" + }, + "elements": [ + { + "name": "Body", + "from": [ 0.0, 0.0, 0.0 ], + "to": [ 16.0, 14.0, 14.0 ], + "faces": { + "north": { "texture": "#0", "uv": [ 0.0, 1.0, 16.0, 15.0 ] }, + "east": { "texture": "#1", "uv": [ 1.0, 1.0, 15.0, 15.0 ] }, + "south": { "texture": "#0", "uv": [ 0.0, 1.0, 16.0, 15.0 ] }, + "west": { "texture": "#1", "uv": [ 1.0, 1.0, 15.0, 15.0 ] }, + "down": { "texture": "#0", "uv": [ 0.0, 1.0, 16.0, 15.0 ] } + } + }, + { + "name": "Top", + "from": [ 0.0, 14.0, 0.0 ], + "to": [ 16.0, 16.0, 15.0 ], + "faces": { + "north": { "texture": "#2", "uv": [ 0.0, 6.0, 16.0, 8.0 ] }, + "east": { "texture": "#2", "uv": [ 1.0, 6.0, 16.0, 8.0 ] }, + "south": { "texture": "#2", "uv": [ 0.0, 6.0, 16.0, 8.0 ] }, + "west": { "texture": "#2", "uv": [ 1.0, 6.0, 16.0, 8.0 ] }, + "up": { "texture": "#2", "uv": [ 0.0, 0.0, 16.0, 15.0 ] }, + "down": { "texture": "#2", "uv": [ 0.0, 1.0, 16.0, 16.0 ], "rotation": 180 } + } + }, + { + "name": "Drawer Body", + "from": [ 1.0, 8.0, 8.0 ], + "to": [ 15.0, 13.0, 15.0 ], + "faces": { + "north": { "texture": "#3", "uv": [ 1.0, 3.0, 15.0, 8.0 ] }, + "east": { "texture": "#3", "uv": [ 7.0, 3.0, 14.0, 8.0 ] }, + "south": { "texture": "#3", "uv": [ 1.0, 7.0, 15.0, 12.0 ] }, + "west": { "texture": "#3", "uv": [ 1.0, 3.0, 8.0, 8.0 ] }, + "up": { "texture": "#3", "uv": [ 1.0, 5.0, 15.0, 12.0 ] }, + "down": { "texture": "#3", "uv": [ 1.0, 3.0, 15.0, 10.0 ] } + } + }, + { + "name": "Drawer Knob", + "from": [ 6.0, 11.0, 14.5 ], + "to": [ 10.0, 12.0, 15.5 ], + "faces": { + "north": { "texture": "#4", "uv": [ 6.0, 6.0, 10.0, 7.0 ] }, + "east": { "texture": "#4", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }, + "south": { "texture": "#4", "uv": [ 6.0, 7.0, 10.0, 8.0 ] }, + "west": { "texture": "#4", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }, + "up": { "texture": "#4", "uv": [ 4.0, 3.0, 8.0, 4.0 ] }, + "down": { "texture": "#4", "uv": [ 6.0, 2.0, 10.0, 3.0 ] } + } + }, + { + "name": "Another Drawer Body", + "from": [ 1.0, 2.0, 8.0 ], + "to": [ 15.0, 7.0, 15.0 ], + "faces": { + "north": { "texture": "#3", "uv": [ 1.0, 0.0, 15.0, 5.0 ] }, + "east": { "texture": "#3", "uv": [ 7.0, 3.0, 14.0, 8.0 ] }, + "south": { "texture": "#3", "uv": [ 1.0, 7.0, 15.0, 12.0 ] }, + "west": { "texture": "#3", "uv": [ 1.0, 3.0, 8.0, 8.0 ] }, + "up": { "texture": "#3", "uv": [ 1.0, 1.0, 15.0, 8.0 ] }, + "down": { "texture": "#3", "uv": [ 1.0, 3.0, 15.0, 10.0 ] } + } + }, + { + "name": "Another Drawer Knob", + "from": [ 6.0, 5.0, 14.5 ], + "to": [ 10.0, 6.0, 15.5 ], + "faces": { + "north": { "texture": "#4", "uv": [ 6.0, 6.0, 10.0, 7.0 ] }, + "east": { "texture": "#4", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }, + "south": { "texture": "#4", "uv": [ 6.0, 7.0, 10.0, 8.0 ] }, + "west": { "texture": "#4", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }, + "up": { "texture": "#4", "uv": [ 4.0, 3.0, 8.0, 4.0 ] }, + "down": { "texture": "#4", "uv": [ 6.0, 2.0, 10.0, 3.0 ] } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/item/shop_shelf.json b/src/main/resources/assets/create/models/item/shop_shelf.json new file mode 100644 index 000000000..ee3b61f03 --- /dev/null +++ b/src/main/resources/assets/create/models/item/shop_shelf.json @@ -0,0 +1,3 @@ +{ + "parent": "create:block/shop_shelf" +} \ No newline at end of file