Skip to content

Commit

Permalink
The facing (+int properties) of IE blocks/TE's can be set using just …
Browse files Browse the repository at this point in the history
…the block state now
  • Loading branch information
malte0811 committed Sep 27, 2017
1 parent ec53e63 commit d7743fa
Show file tree
Hide file tree
Showing 35 changed files with 182 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean canBeReplacedByLeaves(IBlockState state, IBlockAccess world, Bloc


@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
public TileEntity createBasicTE(World worldIn, BlockTypes_FakeLight meta)
{
return new TileEntityFakeLight();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPo
// }

@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
public TileEntity createBasicTE(World worldIn, E meta)
{
return new TileEntityIESlab();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler;
import blusunrize.immersiveengineering.common.util.inventory.IIEInventory;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -49,13 +49,10 @@
import net.minecraftforge.items.IItemHandler;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

@Mod.EventBusSubscriber
public abstract class BlockIETileProvider<E extends Enum<E> & BlockIEBase.IBlockEnum> extends BlockIEBase<E> implements ITileEntityProvider, IColouredBlock
public abstract class BlockIETileProvider<E extends Enum<E> & BlockIEBase.IBlockEnum> extends BlockIEBase<E> implements IColouredBlock
{
private boolean hasColours = false;

Expand All @@ -72,6 +69,42 @@ public static void onTick(TickEvent.ServerTickEvent ev)
tempTile.clear();
}

@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}

@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState state)
{
TileEntity basic = createBasicTE(world, state.getValue(property));
Collection<IProperty<?>> keys = state.getPropertyKeys();
if (basic instanceof IDirectionalTile)
{
if (keys.contains(IEProperties.FACING_HORIZONTAL))
((IDirectionalTile) basic).setFacing(state.getValue(IEProperties.FACING_HORIZONTAL));
else if (keys.contains(IEProperties.FACING_ALL))
((IDirectionalTile) basic).setFacing(state.getValue(IEProperties.FACING_ALL));
}
if (basic instanceof IAttachedIntegerProperies)
{
IAttachedIntegerProperies tileIntProps = (IAttachedIntegerProperies) basic;
String[] names = ((IAttachedIntegerProperies) basic).getIntPropertyNames();
for (String propertyName:names)
{
PropertyInteger property = tileIntProps.getIntProperty(propertyName);
if (keys.contains(property))
tileIntProps.setValue(propertyName, state.getValue(property));
}
}

return basic;
}

@Nullable
public abstract TileEntity createBasicTE(World worldIn, E type);

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
// public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface IAttachedIntegerProperies
String[] getIntPropertyNames();
PropertyInteger getIntProperty(String name);
int getIntPropertyValue(String name);
default void setValue(String name, int value) {}
}

public interface IUsesBooleanProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public boolean allowHammerHarvest(IBlockState state)


@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_ClothDevice type)
{
switch(BlockTypes_ClothDevice.values()[meta])
switch(type)
{
case CUSHION:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public void neighborChanged(IBlockState state, World world, BlockPos pos, Block
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_Connector type)
{
switch(BlockTypes_Connector.values()[meta])
switch(type)
{
case CONNECTOR_LV:
return new TileEntityConnectorLV();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ else if(te instanceof TileEntityConveyorBelt)
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_Conveyor meta)
{
// switch(BlockTypes_Conveyor.values()[meta])
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public boolean isLadder(IBlockState state, IBlockAccess world, BlockPos pos, Ent
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
public TileEntity createBasicTE(World worldIn, BlockTypes_MetalDecoration2 type)
{
switch(BlockTypes_MetalDecoration2.values()[meta])
switch(type)
{
case STEEL_POST:
return new TileEntityWoodenPost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public boolean isSideSolid(IBlockState state, IBlockAccess world, BlockPos pos,
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_MetalDevice0 type)
{
switch(BlockTypes_MetalDevice0.values()[meta])
switch(type)
{
case CAPACITOR_LV:
return new TileEntityCapacitorLV();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ else if(tile instanceof TileEntityTurret)


@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_MetalDevice1 type)
{
switch(BlockTypes_MetalDevice1.values()[meta])
switch(type)
{
case BLAST_FURNACE_PREHEATER:
return new TileEntityBlastFurnacePreheater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public EnumPushReaction getMobilityFlag(IBlockState state)
}

@Override
public TileEntity createNewTileEntity(World world, int meta)
public TileEntity createBasicTE(World world, BlockTypes_MetalMultiblock type)
{
switch(BlockTypes_MetalMultiblock.values()[meta])
switch(type)
{
case METAL_PRESS:
return new TileEntityMetalPress();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.common.IEContent;
Expand Down Expand Up @@ -86,19 +87,20 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
if(!Utils.isBlockAt(world, pos2, IEContent.blockStoneDecoration, BlockTypes_StoneDecoration.ALLOYBRICK.getMeta()))
return false;
}
IBlockState state = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.ALLOY_SMELTER.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, f.getOpposite());
for(int h=0;h<=1;h++)
for(int l=0;l<=1;l++)
for(int w=0;w<=1;w++)
{
BlockPos pos2 = pos.up(h).offset(f,l).offset(f.rotateY(),w);
world.setBlockState(pos2, IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.ALLOY_SMELTER.getMeta()));
world.setBlockState(pos2, state);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityAlloySmelter)
{
TileEntityAlloySmelter currBlast = (TileEntityAlloySmelter) curr;
currBlast.offset=new int[]{pos2.getX()-pos.getX(),pos2.getY()-pos.getY(),pos2.getZ()-pos.getZ()};
currBlast.pos = (h+1)*9 + (l+1)*3 + (w+1);
currBlast.facing=f.getOpposite();
currBlast.formed=true;
currBlast.markDirty();
world.addBlockEvent(pos2, IEContent.blockStoneDevice, 255, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.client.ClientUtils;
Expand Down Expand Up @@ -189,6 +190,8 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit

if(b)
{
IBlockState state = IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.ARC_FURNACE.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, side);
for(int l=0;l<5;l++)
for(int w=-2;w<=2;w++)
for(int h=0;h<5;h++)
Expand All @@ -197,12 +200,11 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
int ww = mirrored?-w:w;
BlockPos pos2 = startPos.offset(side, l).offset(side.rotateY(), ww).add(0, h, 0);

world.setBlockState(pos2, IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.ARC_FURNACE.getMeta()));
world.setBlockState(pos2, state);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityArcFurnace)
{
TileEntityArcFurnace tile = (TileEntityArcFurnace)curr;
tile.facing=side;
tile.formed=true;
tile.pos = h*25 + l*5 + (w+2);
tile.offset = new int[]{(side==EnumFacing.WEST?-l+2: side==EnumFacing.EAST?l-2: side==EnumFacing.NORTH?ww: -ww),h-1,(side==EnumFacing.NORTH?-l+2: side==EnumFacing.SOUTH?l-2: side==EnumFacing.EAST?ww : -ww)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.api.tool.ConveyorHandler;
Expand Down Expand Up @@ -182,19 +183,20 @@ else if(h==1)
}


IBlockState state = IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.ASSEMBLER.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, side);
for(int l=0;l<3;l++)
for(int w=-1;w<=1;w++)
for(int h=-1;h<=1;h++)
{
int ww = mirror?-w:w;
BlockPos pos2 = pos.offset(side, l).offset(side.rotateY(), ww).add(0, h, 0);

world.setBlockState(pos2, IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.ASSEMBLER.getMeta()));
world.setBlockState(pos2, state);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityAssembler)
{
TileEntityAssembler tile = (TileEntityAssembler)curr;
tile.facing=side;
tile.formed=true;
tile.pos = (h+1)*9 + l*3 + (w+1);
tile.offset = new int[]{(side==EnumFacing.WEST?1-l: side==EnumFacing.EAST?l-1: side==EnumFacing.NORTH?ww: -ww),h,(side==EnumFacing.NORTH?1-l: side==EnumFacing.SOUTH?l-1: side==EnumFacing.EAST?ww : -ww)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.api.tool.ConveyorHandler;
Expand Down Expand Up @@ -132,19 +133,20 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit

if(!b)
return false;
IBlockState state = IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.AUTO_WORKBENCH.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, side);
for(int l = 0; l < 3; l++)
for(int w = -1; w <= 1; w++)
for(int h = -1; h <= 0; h++)
{
int ww = mirrored?-w: w;
BlockPos pos2 = pos.offset(side, l).offset(side.rotateY(), ww).add(0, h, 0);

world.setBlockState(pos2, IEContent.blockMetalMultiblock.getStateFromMeta(BlockTypes_MetalMultiblock.AUTO_WORKBENCH.getMeta()));
world.setBlockState(pos2, state);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityAutoWorkbench)
{
TileEntityAutoWorkbench tile = (TileEntityAutoWorkbench)curr;
tile.facing = side;
tile.formed = true;
tile.pos = (h+1)*9+l*3+(w+1);
tile.offset = new int[]{(side==EnumFacing.WEST?1-l: side==EnumFacing.EAST?l-1: side==EnumFacing.NORTH?ww: -ww), h, (side==EnumFacing.NORTH?1-l: side==EnumFacing.SOUTH?l-1: side==EnumFacing.EAST?ww: -ww)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDevices;
import blusunrize.immersiveengineering.common.blocks.stone.TileEntityBlastFurnace;
import blusunrize.immersiveengineering.common.util.Utils;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -82,6 +84,8 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
if(!Utils.isBlockAt(world, pos.add(xx, h, zz), IEContent.blockStoneDecoration, BlockTypes_StoneDecoration.BLASTBRICK.getMeta()))
return false;
}
IBlockState state = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.BLAST_FURNACE.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, f.getOpposite());
for(int h=-1;h<=1;h++)
for(int l=-1;l<=1;l++)
for(int w=-1;w<=1;w++)
Expand All @@ -90,14 +94,13 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
int zz = f==EnumFacing.NORTH?l: f==EnumFacing.SOUTH?-l: f==EnumFacing.EAST?w:-w;

BlockPos pos2 = pos.add(xx, h, zz);
world.setBlockState(pos2, IEContent.blockStoneDevice.getStateFromMeta(1));
world.setBlockState(pos2, state);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityBlastFurnace)
{
TileEntityBlastFurnace currBlast = (TileEntityBlastFurnace) curr;
currBlast.offset=new int[]{xx,h,zz};
currBlast.pos = (h+1)*9 + (l+1)*3 + (w+1);
currBlast.facing=f.getOpposite();
currBlast.formed=true;
currBlast.markDirty();
world.addBlockEvent(pos2, IEContent.blockStoneDevice, 255, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package blusunrize.immersiveengineering.common.blocks.multiblocks;

import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDevices;
import blusunrize.immersiveengineering.common.blocks.stone.TileEntityBlastFurnace;
import blusunrize.immersiveengineering.common.util.Utils;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -110,6 +112,8 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
}
}

IBlockState state = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.BLAST_FURNACE_ADVANCED.getMeta());
state = state.withProperty(IEProperties.FACING_HORIZONTAL, f.getOpposite());
for(int h=-1;h<=2;h++)
for(int l=-1;l<=1;l++)
for(int w=-1;w<=1;w++)
Expand All @@ -118,15 +122,14 @@ public boolean createStructure(World world, BlockPos pos, EnumFacing side, Entit
int xx = f==EnumFacing.EAST?l: f==EnumFacing.WEST?-l: f==EnumFacing.NORTH?-w:w;
int zz = f==EnumFacing.NORTH?l: f==EnumFacing.SOUTH?-l: f==EnumFacing.EAST?w:-w;

world.setBlockState(pos.add(xx, h, zz), IEContent.blockStoneDevice.getStateFromMeta(2));
world.setBlockState(pos.add(xx, h, zz), state);
BlockPos pos2 = pos.add(xx, h, zz);
TileEntity curr = world.getTileEntity(pos2);
if(curr instanceof TileEntityBlastFurnace)
{
TileEntityBlastFurnace currBlast = (TileEntityBlastFurnace) curr;
currBlast.offset=new int[]{xx,h,zz};
currBlast.pos = (h+1)*9 + (l+1)*3 + (w+1);
currBlast.facing=f.getOpposite();
currBlast.formed=true;
currBlast.markDirty();
world.addBlockEvent(pos2, IEContent.blockStoneDevice, 255, 0);
Expand Down
Loading

0 comments on commit d7743fa

Please sign in to comment.