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