mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-26 06:52:58 +00:00
Multiblocks are complicated :<
This commit is contained in:
1 parent
e267fd4d26
commit
5d812da5a1
8 files changed
+210
-2
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Jun 9, 2014, 7:17:46 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.lexicon.ILexiconable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.wand.IWandable;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.block.tile.TileAlfPortal;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
|
||||
public class BlockAlfPortal extends BlockModContainer implements IWandable, ILexiconable {
|
||||
|
||||
IIcon iconOff, iconOn;
|
||||
|
||||
public BlockAlfPortal() {
|
||||
super(Material.wood);
|
||||
setHardness(10F);
|
||||
setStepSound(soundTypeWood);
|
||||
setBlockName(LibBlockNames.ALF_PORTAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
iconOff = IconHelper.forBlock(par1IconRegister, this, 0);
|
||||
iconOn = IconHelper.forBlock(par1IconRegister, this, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
return meta == 0 ? iconOff : iconOn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TileAlfPortal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LexiconEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
|
||||
return LexiconData.alfhomancyIntro;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side) {
|
||||
return ((TileAlfPortal) world.getTileEntity(x, y, z)).onWanded();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import vazkii.botania.common.block.subtile.generating.SubTileKekimurus;
|
||||
import vazkii.botania.common.block.subtile.generating.SubTileMunchdew;
|
||||
import vazkii.botania.common.block.subtile.generating.SubTileNightshade;
|
||||
import vazkii.botania.common.block.subtile.generating.SubTileThermalily;
|
||||
import vazkii.botania.common.block.tile.TileAlfPortal;
|
||||
import vazkii.botania.common.block.tile.TileAltar;
|
||||
import vazkii.botania.common.block.tile.TileEnchanter;
|
||||
import vazkii.botania.common.block.tile.TileForestEye;
|
||||
@@ -97,6 +98,7 @@ public final class ModBlocks {
|
||||
public static Block forestDrum;
|
||||
public static Block shinyFlower;
|
||||
public static Block platform;
|
||||
public static Block alfPortal;
|
||||
|
||||
public static void init() {
|
||||
flower = new BlockModFlower();
|
||||
@@ -124,6 +126,7 @@ public final class ModBlocks {
|
||||
forestDrum = new BlockForestDrum();
|
||||
shinyFlower = new BlockShinyFlower();
|
||||
platform = new BlockPlatform();
|
||||
alfPortal = new BlockAlfPortal();
|
||||
|
||||
for(int i = 0; i < 16; i++)
|
||||
OreDictionary.registerOre(LibOreDict.FLOWER[i], new ItemStack(flower, 1, i));
|
||||
@@ -157,6 +160,7 @@ public final class ModBlocks {
|
||||
registerTile(TileOpenCrate.class, LibBlockNames.OPEN_CRATE);
|
||||
registerTile(TileForestEye.class, LibBlockNames.FOREST_EYE);
|
||||
registerTile(TilePlatform.class, LibBlockNames.PLATFORM);
|
||||
registerTile(TileAlfPortal.class, LibBlockNames.ALF_PORTAL);
|
||||
|
||||
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class);
|
||||
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class);
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Jun 9, 2014, 8:51:55 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
public class TileAlfPortal extends TileEntity {
|
||||
|
||||
private static final int[][] LIVINGWOOD_POSITIONS = {
|
||||
{ -1, 0, 0}, { 1, 0, 0}, { -2, 1, 0}, { 2, 1, 0}, { -2, 3, 0}, { 2, 3, 0}, { -1, 4, 0}, { 1, 4, 0}
|
||||
};
|
||||
|
||||
private static final int[][] GLIMMERING_LIVINGWOOD_POSITIONS = {
|
||||
{ -2, 2, 0 }, { 2, 2, 0 }, { 0, 4, 0 }
|
||||
};
|
||||
|
||||
private static final int[][] PYLON_POSITIONS = {
|
||||
{ -3, 1, 3 }, { 3, 1, 3 }
|
||||
};
|
||||
|
||||
private static final int[][] POOL_POSITIONS = {
|
||||
{ -3, 0, 3 }, { 3, 0, 3 }
|
||||
};
|
||||
|
||||
private static final Function<int[], int[]> CONVERTER_X_Z = new Function<int[], int[]>() {
|
||||
@Override
|
||||
public int[] apply(int[] input) {
|
||||
return new int[] { input[2], input[1], input[0] };
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function<int[], int[]> CONVERTER_Z_SWAP = new Function<int[], int[]>() {
|
||||
@Override
|
||||
public int[] apply(int[] input) {
|
||||
return new int[] { input[0], input[1], -input[2] };
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
int meta = getBlockMetadata();
|
||||
if(meta == 0)
|
||||
return;
|
||||
|
||||
int newMeta = getValidMetadata();
|
||||
if(newMeta != meta)
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2);
|
||||
|
||||
}
|
||||
|
||||
public boolean onWanded() {
|
||||
int meta = getBlockMetadata();
|
||||
if(meta == 0) {
|
||||
int newMeta = getValidMetadata();
|
||||
if(newMeta != 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getValidMetadata() {
|
||||
if(checkConverter(null))
|
||||
return 1;
|
||||
|
||||
if(checkConverter(CONVERTER_X_Z))
|
||||
return 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean checkConverter(Function<int[], int[]> baseConverter) {
|
||||
return checkMultipleConverters(baseConverter) || checkMultipleConverters(CONVERTER_Z_SWAP, baseConverter);
|
||||
}
|
||||
|
||||
private boolean checkMultipleConverters(Function<int[], int[]>... converters) {
|
||||
if(!check2DArray(LIVINGWOOD_POSITIONS, ModBlocks.livingwood, 0, converters))
|
||||
return false;
|
||||
if(!check2DArray(GLIMMERING_LIVINGWOOD_POSITIONS, ModBlocks.livingwood, 5, converters))
|
||||
return false;
|
||||
if(!check2DArray(PYLON_POSITIONS, ModBlocks.pylon, 0, converters))
|
||||
return false;
|
||||
if(!check2DArray(POOL_POSITIONS, ModBlocks.pool, -1, converters))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean check2DArray(int[][] positions, Block block, int meta, Function<int[], int[]>... converters) {
|
||||
for(int[] pos : positions) {
|
||||
for(Function<int[], int[]> f : converters)
|
||||
if(f != null)
|
||||
pos = f.apply(pos);
|
||||
|
||||
if(!checkPosition(pos, block, meta))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkPosition(int[] pos, Block block, int meta) {
|
||||
int x = xCoord + pos[0];
|
||||
int y = yCoord + pos[1];
|
||||
int z = zCoord + pos[2];
|
||||
Block blockat = worldObj.getBlock(x, y, z);
|
||||
if(blockat == block) {
|
||||
if(meta == -1)
|
||||
return true;
|
||||
|
||||
int metaat = worldObj.getBlockMetadata(x, y, z);
|
||||
return meta == metaat;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
|
||||
addItem(ModItems.grassHorn);
|
||||
addBlock(ModBlocks.forestDrum);
|
||||
addBlock(ModBlocks.forestEye);
|
||||
addBlock(ModBlocks.alfPortal);
|
||||
|
||||
addBlock(ModBlocks.livingrock);
|
||||
addBlock(ModBlocks.livingwood);
|
||||
|
||||
@@ -39,6 +39,7 @@ public final class LibBlockNames {
|
||||
public static final String FOREST_DRUM = "forestDrum";
|
||||
public static final String SHINY_FLOWER = "shinyFlower";
|
||||
public static final String PLATFORM = "platform";
|
||||
public static final String ALF_PORTAL = "alfheimPortal";
|
||||
|
||||
public static final String SPECIAL_FLOWER_PREFIX = FLOWER + ".";
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ botania.color14=Red
|
||||
botania.color15=Black
|
||||
botania.color16=Rainbow
|
||||
|
||||
# -- RANKS
|
||||
# RANKS
|
||||
botania.rank0=&cD
|
||||
botania.rank1=&eC
|
||||
botania.rank2=&bB
|
||||
@@ -53,7 +53,7 @@ botania.rank3=&aA
|
||||
botania.rank4=&dS
|
||||
botania.rank5=&6SS
|
||||
|
||||
# -- VERSION CHECKING
|
||||
# VERSION CHECKING
|
||||
botania.versioning.flavour0=NANI SORE!? BOTANIA IS OUTDATED!?
|
||||
botania.versioning.flavour1=What do you mean Botania is outdated, you ignorant fool?
|
||||
botania.versioning.flavour2=It's not like Botania wants to be outdated, b-b-BAKA!
|
||||
@@ -183,6 +183,7 @@ tile.botania:shinyFlower13.name=Glimmering Green Flower
|
||||
tile.botania:shinyFlower14.name=Glimmering Red Flower
|
||||
tile.botania:shinyFlower15.name=Glimmering Black Flower
|
||||
tile.botania:platform.name=Abtruse Platform
|
||||
tile.botania:alfheimPortal.name=World Tree Extract
|
||||
|
||||
# FLOWER NAMES
|
||||
tile.botania:flower..name=Botania Flower
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"animation": { }
|
||||
}
|
||||
Reference in new issue
Block a user