First 1.8.9 Version

This commit is contained in:
Nedelosk committed 2016-01-22 19:33:35 +01:00
1 parent d35cc1df09
commit 5a3850c264
1657 files changed
+26844 -13269

No files matched your search

@@ -11,24 +11,34 @@
package forestry.apiculture.blocks;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.IModelManager;
import forestry.api.core.IStateMapperRegister;
import forestry.api.core.Tabs;
import forestry.apiculture.MaterialBeehive;
import forestry.apiculture.multiblock.TileAlveary;
import forestry.apiculture.multiblock.TileAlvearyClimatiser;
import forestry.apiculture.multiblock.TileAlvearyFan;
import forestry.apiculture.multiblock.TileAlvearyHeater;
import forestry.apiculture.multiblock.TileAlvearyHygroregulator;
@@ -37,20 +47,47 @@ import forestry.apiculture.multiblock.TileAlvearySieve;
import forestry.apiculture.multiblock.TileAlvearyStabiliser;
import forestry.apiculture.multiblock.TileAlvearySwarmer;
import forestry.core.blocks.BlockStructure;
import forestry.core.render.TextureManager;
import forestry.core.proxy.Proxies;
public class BlockAlveary extends BlockStructure {
public enum Type {
public class BlockAlveary extends BlockStructure implements IStateMapperRegister {
private static final PropertyEnum TYPE = PropertyEnum.create("alveary", Type.class);
private static final PropertyEnum STATE = PropertyEnum.create("state", State.class);
private static final PropertyEnum LEVEL = PropertyEnum.create("type", Level.class);
private enum State implements IStringSerializable {
ON, OFF;
@Override
public String getName() {
return name().toLowerCase();
}
}
private enum Level implements IStringSerializable {
BOTTOM, LEFT, RIGHT;
@Override
public String getName() {
return name().toLowerCase();
}
}
public enum Type implements IStringSerializable {
PLAIN,
ENTRANCE,
SWARMER,
FAN,
HEATER,
HYGRO,
STABILIZER,
STABILISER,
SIEVE;
public static final Type[] VALUES = values();
@Override
public String getName() {
return name().toLowerCase();
}
}
public BlockAlveary() {
@@ -58,6 +95,7 @@ public class BlockAlveary extends BlockStructure {
setHardness(1.0f);
setCreativeTab(Tabs.tabApiculture);
setHarvestLevel("axe", 0);
setDefaultState(this.blockState.getBaseState().withProperty(TYPE, Type.PLAIN).withProperty(STATE, State.OFF).withProperty(LEVEL, Level.BOTTOM));
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -74,30 +112,31 @@ public class BlockAlveary extends BlockStructure {
@Override
public int getRenderType() {
return 0;
return 3;
}
@Override
public boolean renderAsNormalBlock() {
public boolean isNormalCube() {
return true;
}
@Override
public boolean isFullCube() {
return true;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
int metadata = getMetaFromState(state);
ArrayList<ItemStack> drop = new ArrayList<>();
drop.add(new ItemStack(this, 1, metadata != 1 ? metadata : 0));
return drop;
}
@Override
public int getDamageValue(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
return meta != 1 ? meta : 0;
}
/* TILE ENTITY CREATION */
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createTileEntity(World world, IBlockState state) {
int metadata = getMetaFromState(state);
if (metadata < 0 || metadata > Type.VALUES.length) {
return null;
}
@@ -112,7 +151,7 @@ public class BlockAlveary extends BlockStructure {
return new TileAlvearyHeater();
case HYGRO:
return new TileAlvearyHygroregulator();
case STABILIZER:
case STABILISER:
return new TileAlvearyStabiliser();
case SIEVE:
return new TileAlvearySieve();
@@ -124,159 +163,146 @@ public class BlockAlveary extends BlockStructure {
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return createTileEntity(world, meta);
return createTileEntity(world, getStateFromMeta(meta));
}
/* ICONS */
public static final int PLAIN = 0;
public static final int ENTRANCE = 1;
public static final int BOTTOM = 2;
public static final int LEFT = 3;
public static final int RIGHT = 4;
public static final int ALVEARY_SWARMER_OFF = 5;
public static final int ALVEARY_SWARMER_ON = 6;
public static final int ALVEARY_HEATER_OFF = 7;
public static final int ALVEARY_HEATER_ON = 8;
public static final int ALVEARY_FAN_OFF = 9;
public static final int ALVEARY_FAN_ON = 10;
public static final int ALVEARY_HYGRO = 11;
public static final int STABILISER = 12;
public static final int SIEVE = 13;
@SideOnly(Side.CLIENT)
private IIcon[] icons;
/* ITEM MODELS */
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister register) {
icons = new IIcon[14];
icons[0] = TextureManager.registerTex(register, "apiculture/alveary.plain");
icons[1] = TextureManager.registerTex(register, "apiculture/alveary.entrance");
icons[2] = TextureManager.registerTex(register, "apiculture/alveary.bottom");
icons[3] = TextureManager.registerTex(register, "apiculture/alveary.left");
icons[4] = TextureManager.registerTex(register, "apiculture/alveary.right");
icons[5] = TextureManager.registerTex(register, "apiculture/alveary.swarmer.off");
icons[6] = TextureManager.registerTex(register, "apiculture/alveary.swarmer.on");
icons[7] = TextureManager.registerTex(register, "apiculture/alveary.heater.off");
icons[8] = TextureManager.registerTex(register, "apiculture/alveary.heater.on");
icons[9] = TextureManager.registerTex(register, "apiculture/alveary.fan.off");
icons[10] = TextureManager.registerTex(register, "apiculture/alveary.fan.on");
icons[11] = TextureManager.registerTex(register, "apiculture/alveary.valve");
icons[12] = TextureManager.registerTex(register, "apiculture/alveary.stabiliser");
icons[13] = TextureManager.registerTex(register, "apiculture/alveary.sieve");
public void registerModel(Item item, IModelManager manager) {
manager.registerItemModel(item, 0, "apiculture/alveary.plain");
manager.registerItemModel(item, 1, "apiculture/alveary.entrance");
manager.registerItemModel(item, 2, "apiculture/alveary.swarmer");
manager.registerItemModel(item, 3, "apiculture/alveary.fan");
manager.registerItemModel(item, 4, "apiculture/alveary.heater");
manager.registerItemModel(item, 5, "apiculture/alveary.hygro");
manager.registerItemModel(item, 6, "apiculture/alveary.stabiliser");
manager.registerItemModel(item, 7, "apiculture/alveary.sieve");
}
/* STATES */
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TYPE, Type.values()[meta]);
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int metadata) {
if ((metadata <= 1
|| metadata == Type.SIEVE.ordinal() || metadata == Type.SWARMER.ordinal() || metadata == Type.STABILIZER.ordinal())
&& (side == 1 || side == 0)) {
return icons[BOTTOM];
}
Type type = Type.VALUES[metadata];
switch (type) {
case PLAIN:
return icons[PLAIN];
case ENTRANCE:
return icons[ENTRANCE];
case SWARMER:
return icons[ALVEARY_SWARMER_OFF];
case FAN:
return icons[ALVEARY_FAN_OFF];
case HEATER:
return icons[ALVEARY_HEATER_OFF];
case HYGRO:
return icons[ALVEARY_HYGRO];
case STABILIZER:
return icons[STABILISER];
case SIEVE:
return icons[SIEVE];
default:
return null;
}
public int getMetaFromState(IBlockState state) {
return ((Type) state.getValue(TYPE)).ordinal();
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 1) {
return this.getIcon(side, meta);
} else if (meta > 1) {
return getBlockTextureFromSideAndTile(world, x, y, z, side);
protected BlockState createBlockState() {
return new BlockState(this, new IProperty[] { TYPE, STATE, LEVEL });
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileAlveary) {
if (tile instanceof TileAlvearyClimatiser) {
TileAlvearyClimatiser alveary = (TileAlvearyClimatiser) tile;
if (alveary.isActive()) {
state = state.withProperty(STATE, State.ON);
} else {
state = state.withProperty(STATE, State.OFF);
}
} else if (tile instanceof TileAlvearySwarmer) {
TileAlvearySwarmer alveary = (TileAlvearySwarmer) tile;
if (alveary.isActive()) {
state = state.withProperty(STATE, State.ON);
} else {
state = state.withProperty(STATE, State.OFF);
}
}
}
Block blockXP = world.getBlock(x + 1, y, z);
Block blockXM = world.getBlock(x - 1, y, z);
int meta = ((Type) state.getValue(TYPE)).ordinal();
Block blockXP = world.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getBlock();
Block blockXM = world.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getBlock();
state = state.withProperty(LEVEL, Level.BOTTOM);
if (blockXP == this && blockXM != this) {
if (world.getBlockMetadata(x + 1, y, z) == 1) {
IBlockState stateNeighbor = world.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()));
if (stateNeighbor.getBlock().getMetaFromState(stateNeighbor) == 1) {
if (world.getBlock(x, y, z + 1) != this) {
return switchForSide(42, side);
if (world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock() != this) {
switchForSide(state, world, pos);
} else {
return switchForSide(41, side);
switchForSide(state, world, pos);
}
} else {
return this.getIcon(side, meta);
}
} else if (blockXP != this && blockXM == this) {
if (world.getBlockMetadata(x - 1, y, z) == 1) {
IBlockState stateNeighbor = world.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()));
if (stateNeighbor.getBlock().getMetaFromState(stateNeighbor) == 1) {
if (world.getBlock(x, y, z + 1) != this) {
return switchForSide(41, side);
if (world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock() != this) {
switchForSide(state, world, pos);
} else {
return switchForSide(42, side);
switchForSide(state, world, pos);
}
} else {
return this.getIcon(side, meta);
}
}
return this.getIcon(side, meta);
return super.getActualState(state, world, pos);
}
private void switchForSide(IBlockState state, IBlockAccess world, BlockPos pos) {
@SideOnly(Side.CLIENT)
private IIcon getBlockTextureFromSideAndTile(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileAlveary)) {
return getIcon(side, 0);
Block blockX = world.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getBlock();
Block blockY = world.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock();
if (blockX != this && blockY == this) {
state = state.withProperty(LEVEL, Level.LEFT);
} else if (blockX == this && blockY == this) {
state = state.withProperty(LEVEL, Level.RIGHT);
} else if (blockX == this && blockY != this) {
state = state.withProperty(LEVEL, Level.LEFT);
} else if (blockX != this && blockY != this) {
state = state.withProperty(LEVEL, Level.RIGHT);
}
return icons[((TileAlveary) tile).getIcon(side)];
}
@Override
public void registerStateMapper() {
Proxies.render.registerStateMapper(this, new AlvearyStateMapper());
}
@SideOnly(Side.CLIENT)
private IIcon switchForSide(int textureId, int side) {
private static class AlvearyStateMapper extends StateMapperBase {
if (side == 4 || side == 5) {
if (textureId == 41) {
return icons[LEFT];
} else {
return icons[RIGHT];
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
LinkedHashMap linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
if (linkedhashmap.get(TYPE) != Type.PLAIN) {
linkedhashmap.remove(LEVEL);
}
} else if (textureId == 41) {
return icons[RIGHT];
} else {
return icons[LEFT];
if (linkedhashmap.get(TYPE) == Type.SIEVE
|| linkedhashmap.get(TYPE) == Type.ENTRANCE
|| linkedhashmap.get(TYPE) == Type.STABILISER
|| linkedhashmap.get(TYPE) == Type.HYGRO
|| linkedhashmap.get(TYPE) == Type.PLAIN) {
linkedhashmap.remove(STATE);
}
String s = String.format("%s:%s",
Block.blockRegistry.getNameForObject(state.getBlock()).getResourceDomain(),
"apiculture/alveary_" + TYPE.getName((Enum) linkedhashmap.remove(TYPE)));
;
return new ModelResourceLocation(s, this.getPropertyString(linkedhashmap));
}
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
super.onNeighborBlockChange(world, x, y, z, block);
TileEntity tileEntity = world.getTileEntity(x, y, z);
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock) {
super.onNeighborBlockChange(world, pos, state, neighborBlock);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileAlveary) {
TileAlveary tileAlveary = (TileAlveary) tileEntity;