Skip to content

Commit

Permalink
Mantlify Redstone Machines a bit more, update firestarter blockstate …
Browse files Browse the repository at this point in the history
…to use proper forge syntax.
  • Loading branch information
fuj1n committed Jul 30, 2016
1 parent c280977 commit 76b33a5
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 89 deletions.
89 changes: 34 additions & 55 deletions resources/assets/tmechworks/blockstates/firestarter.json
Expand Up @@ -2,65 +2,44 @@
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"model": "cube_all",
"model": "tmechworks:machine_base",
"textures": {
"all": "tmechworks:blocks/machines/firestarter_side",
"particle": "#all"
"face": "tmechworks:blocks/machines/firestarter_face",
"back": "tmechworks:blocks/machines/firestarter_back",
"side": "tmechworks:/blocks/machines/firestarter_side"
}
},
"variants": {
"inventory": {
"model": "tmechworks:firestarter"
},
"extinguish=false,facing=north": {
"model": "tmechworks:firestarter",
"x": 90
},
"extinguish=false,facing=south": {
"model": "tmechworks:firestarter",
"x": -90
},
"extinguish=false,facing=west": {
"model": "tmechworks:firestarter",
"x": 90,
"y": -90
},
"extinguish=false,facing=east": {
"model": "tmechworks:firestarter",
"x": 90,
"y": 90
},
"extinguish=false,facing=up": {
"model": "tmechworks:firestarter"
},
"extinguish=false,facing=down": {
"model": "tmechworks:firestarter",
"x": 180
},
"extinguish=true,facing=north": {
"model": "tmechworks:firestarter_extinguish",
"x": 90
},
"extinguish=true,facing=south": {
"model": "tmechworks:firestarter_extinguish",
"x": -90
},
"extinguish=true,facing=west": {
"model": "tmechworks:firestarter_extinguish",
"x": 90,
"y": -90
},
"extinguish=true,facing=east": {
"model": "tmechworks:firestarter_extinguish",
"x": 90,
"y": 90
},
"extinguish=true,facing=up": {
"model": "tmechworks:firestarter_extinguish"
},
"extinguish=true,facing=down": {
"model": "tmechworks:firestarter_extinguish",
"x": 180
"extinguish": {
"false": {},
"true": {
"textures": {
"side": "tmechworks:/blocks/machines/firestarter_side_extinguish"
}
}
},
"facing": {
"north": {
"x": 90
},
"south": {
"x": -90
},
"west": {
"x": 90,
"y": -90
},
"east": {
"x": 90,
"y": 90
},
"up": {},
"down": {
"x": 180
}
},
"type": {
"normal": {}
}
}
}
2 changes: 1 addition & 1 deletion resources/assets/tmechworks/lang/en_US.lang
Expand Up @@ -3,7 +3,7 @@
tile.tmechworks.drawbridge.normal.name=Drawbridge
tile.tmechworks.drawbridge.advanced.name=Advanced Drawbridge
tile.tmechworks.drawbridge.extended.name=Extended Drawbridge
tile.tmechworks.firestarter.name=Firestarter
tile.tmechworks.firestarter.normal.name=Firestarter

## Compressed Blocks
tile.tmechworks.metal.aluminum.name=Aluminum Block
Expand Down
3 changes: 2 additions & 1 deletion resources/assets/tmechworks/models/block/drawbridge.json
Expand Up @@ -4,5 +4,6 @@
"face": "tmechworks:blocks/machines/drawbridge_face",
"back": "tmechworks:blocks/machines/drawbridge_back",
"side": "tmechworks:/blocks/machines/drawbridge_side"
}
},
"comment": "This model is temporary to provide a model for the item, will be deleted after I figure out why it doesn't read the blockstate for the item model."
}
3 changes: 2 additions & 1 deletion resources/assets/tmechworks/models/block/firestarter.json
Expand Up @@ -4,5 +4,6 @@
"face": "tmechworks:blocks/machines/firestarter_face",
"back": "tmechworks:blocks/machines/firestarter_back",
"side": "tmechworks:/blocks/machines/firestarter_side"
}
},
"comment": "This model is temporary to provide a model for the item, will be deleted after I figure out why it doesn't read the blockstate for the item model."
}

This file was deleted.

15 changes: 2 additions & 13 deletions src/main/java/slimeknights/tmechworks/blocks/Drawbridge.java
@@ -1,6 +1,5 @@
package slimeknights.tmechworks.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
Expand All @@ -21,13 +20,13 @@
import java.util.List;
import java.util.Locale;

public class Drawbridge extends RedstoneMachine implements IEnumBlock<Drawbridge.DrawbridgeType>
public class Drawbridge extends RedstoneMachine<Drawbridge.DrawbridgeType>
{
public static final PropertyEnum<DrawbridgeType> TYPE = PropertyEnum.create("type", DrawbridgeType.class, DrawbridgeType.values());

public Drawbridge ()
{
super(Material.IRON);
super(Material.IRON, TYPE, DrawbridgeType.class);
this.setDefaultState(this.getDefaultState().withProperty(TYPE, DrawbridgeType.NORMAL));
}

Expand Down Expand Up @@ -60,16 +59,6 @@ public Drawbridge ()
return new BlockStateContainer(this, FACING, TYPE);
}

@Override public PropertyEnum<DrawbridgeType> getProperty ()
{
return TYPE;
}

@Override public Block getSelf ()
{
return this;
}

@SideOnly(Side.CLIENT) public void getSubBlocks (Item itemIn, CreativeTabs tab, List<ItemStack> list)
{
list.add(new ItemStack(itemIn, 1, 0));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/slimeknights/tmechworks/blocks/Firestarter.java
Expand Up @@ -19,13 +19,13 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class Firestarter extends RedstoneMachine
public class Firestarter extends RedstoneMachine<RedstoneMachine.DefaultTypes>
{
public static final PropertyBool SHOULD_EXTENGUISH = PropertyBool.create("extinguish");

public Firestarter ()
{
super(Material.IRON);
super(Material.IRON, DEF_TYPE, DefaultTypes.class);
}

@Override public IBlockState getActualState (@Nonnull IBlockState state, IBlockAccess worldIn, BlockPos pos)
Expand All @@ -44,7 +44,7 @@ public Firestarter ()

@Nonnull @Override protected BlockStateContainer createBlockState ()
{
return new BlockStateContainer(this, FACING, SHOULD_EXTENGUISH);
return new BlockStateContainer(this, FACING, SHOULD_EXTENGUISH, DEF_TYPE);
}

@Nonnull @Override public TileEntity createNewTileEntity (@Nonnull World worldIn, int meta)
Expand Down
115 changes: 109 additions & 6 deletions src/main/java/slimeknights/tmechworks/blocks/RedstoneMachine.java
Expand Up @@ -2,42 +2,52 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import slimeknights.mantle.block.BlockInventory;
import slimeknights.mantle.block.EnumBlock;
import slimeknights.mantle.tileentity.TileInventory;
import slimeknights.tmechworks.TMechworks;
import slimeknights.tmechworks.blocks.logic.RedstoneMachineLogicBase;

import javax.annotation.Nonnull;

public abstract class RedstoneMachine extends BlockInventory
public abstract class RedstoneMachine<E extends Enum<E> & EnumBlock.IEnumMeta & IStringSerializable> extends EnumBlock<E> implements ITileEntityProvider
{
public static final PropertyEnum<DefaultTypes> DEF_TYPE = PropertyEnum.create("type", DefaultTypes.class);
public static final PropertyDirection FACING = PropertyDirection.create("facing");

protected RedstoneMachine (Material material)
protected RedstoneMachine(Material material, PropertyEnum<E> prop, Class<E> clazz)
{
super(material);
super(material, prop, clazz);
this.isBlockContainer = true;
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}

@Override protected boolean openGui (EntityPlayer player, World world, BlockPos pos)
protected boolean openGui(EntityPlayer player, World world, BlockPos pos)
{
player.openGui(TMechworks.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
return true;
}

@Override @Nonnull protected BlockStateContainer createBlockState ()
{
return new BlockStateContainer(this, FACING);
return new BlockStateContainer(this, prop, FACING);
}

@Override public IBlockState getActualState (@Nonnull IBlockState state, IBlockAccess worldIn, BlockPos pos)
Expand Down Expand Up @@ -71,6 +81,17 @@ public boolean hasFacingDirection ()

@Override public void onBlockPlacedBy (World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);

// set custom name from named stack
if (stack.hasDisplayName()) {
TileEntity tileentity = worldIn.getTileEntity(pos);

if (tileentity instanceof TileInventory) {
((TileInventory) tileentity).setCustomName(stack.getDisplayName());
}
}

if (!hasFacingDirection())
return;

Expand All @@ -93,4 +114,86 @@ public boolean hasFacingDirection ()
{
return getDefaultState();
}

/////////////////////////
// BlockContainer Code //
/////////////////////////

protected boolean isInvalidNeighbor(World worldIn, BlockPos pos, EnumFacing facing) {
return worldIn.getBlockState(pos.offset(facing)).getMaterial() == Material.CACTUS;
}

protected boolean hasInvalidNeighbor(World worldIn, BlockPos pos) {
return this.isInvalidNeighbor(worldIn, pos, EnumFacing.NORTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.SOUTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.WEST) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.EAST);
}

/**
* Called on both Client and Server when World#addBlockEvent is called. On the Server, this may perform additional
* changes to the world, like pistons replacing the block with an extended base. On the client, the update may
* involve replacing tile entities, playing sounds, or performing other visual actions to reflect the server side
* changes.
*/
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
super.eventReceived(state, worldIn, pos, id, param);
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity != null && tileentity.receiveClientEvent(id, param);
}

/////////////////////////
// BlockInventory Code //
/////////////////////////

// inventories usually need a tileEntity
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}

@Nonnull
@Override
public abstract TileEntity createNewTileEntity(@Nonnull World worldIn, int meta);

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float clickX, float clickY, float clickZ) {
if (player.isSneaking()) {
return false;
}

if (!world.isRemote) {
return this.openGui(player, world, pos);
}

return true;
}

@Override
public void breakBlock(World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
TileEntity tileentity = worldIn.getTileEntity(pos);

if (tileentity instanceof TileInventory) {
InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory) tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}

super.breakBlock(worldIn, pos, state);
}

@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}

public enum DefaultTypes implements IEnumMeta, IStringSerializable {
NORMAL;

@Override
public String getName() {
return toString().toLowerCase();
}

@Override
public int getMeta() {
return ordinal();
}
}
}
Expand Up @@ -83,7 +83,7 @@ private void registerBlocks ()
drawbridge.setCreativeTab(tabMechworks);
registerTE(DrawbridgeLogic.class, "drawbridge");

firestarter = registerBlock(new Firestarter(), "firestarter");
firestarter = registerEnumBlock(new Firestarter(), "firestarter");
firestarter.setCreativeTab(tabMechworks);
registerTE(FirestarterLogic.class, "firestarter");
}
Expand Down

0 comments on commit 76b33a5

Please sign in to comment.