Shopping with Mike part 1

- Added Shelf Block, Tile Entity, Container, Screen, Model
This commit is contained in:
simibubi 2019-08-08 23:10:01 +02:00
parent 25309e40b4
commit 8ac10da276
14 changed files with 354 additions and 12 deletions

View file

@ -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;

View file

@ -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<? extends Container> 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)

View file

@ -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)))),
ANDESITE_ALLOY_CUBE(new Item(standardProperties())), BLAZE_BRASS_CUBE(new Item(standardProperties())),
PLACEMENT_HANDGUN(
new BuilderGunItem(new Properties().setTEISR(() -> () -> renderUsing(AllItemRenderers.BUILDER_GUN)))),
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,14 +73,24 @@ 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();
default:
return null;
}
}
@SubscribeEvent
@OnlyIn(Dist.CLIENT)

View file

@ -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);

View file

@ -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

View file

@ -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<Block, BlockState> 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);
}
}

View file

@ -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;
}
}

View file

@ -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<ShopShelfContainer> {
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);
}
}

View file

@ -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());
}
}

View file

@ -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

View file

@ -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 }
}
}

View file

@ -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"
}

View file

@ -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 ] }
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"parent": "create:block/shop_shelf"
}