diff --git a/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java b/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java index 70c81e46f..f85ab0735 100644 --- a/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java +++ b/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java @@ -41,6 +41,8 @@ public class SubTileGenerating extends SubTileEntity { private static final String TAG_COLLECTOR_Z = "collectorZ"; protected int mana; + + public int redstoneSignal = 0; int sizeLastCheck = -1; protected TileEntity linkedCollector = null; @@ -48,6 +50,13 @@ public class SubTileGenerating extends SubTileEntity { ChunkCoordinates cachedCollectorCoordinates = null; + /** + * If set to true, redstoneSignal will be updated every tick. + */ + public boolean acceptsRedstone() { + return false; + } + @Override public void onUpdate() { super.onUpdate(); @@ -64,6 +73,14 @@ public class SubTileGenerating extends SubTileEntity { } emptyManaIntoCollector(); + if(acceptsRedstone()) { + redstoneSignal = 0; + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + int redstoneSide = supertile.getWorldObj().getIndirectPowerLevelTo(supertile.xCoord + dir.offsetX, supertile.yCoord + dir.offsetY, supertile.zCoord + dir.offsetZ, dir.ordinal()); + redstoneSignal = Math.max(redstoneSignal, redstoneSide); + } + } + if(supertile.getWorldObj().isRemote) { double particleChance = 1F - (double) mana / (double) getMaxMana() / 3.5F; Color color = new Color(getColor()); diff --git a/src/main/java/vazkii/botania/client/core/handler/SubTileRadiusRenderHandler.java b/src/main/java/vazkii/botania/client/core/handler/SubTileRadiusRenderHandler.java index 22e691ca9..620a2cfc9 100644 --- a/src/main/java/vazkii/botania/client/core/handler/SubTileRadiusRenderHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/SubTileRadiusRenderHandler.java @@ -53,7 +53,6 @@ public final class SubTileRadiusRenderHandler { y = coords.posY; z = coords.posZ; } - } TileEntity tile = mc.theWorld.getTileEntity(x, y, z); diff --git a/src/main/java/vazkii/botania/common/block/BlockCell.java b/src/main/java/vazkii/botania/common/block/BlockCell.java new file mode 100644 index 000000000..555f6c912 --- /dev/null +++ b/src/main/java/vazkii/botania/common/block/BlockCell.java @@ -0,0 +1,39 @@ +/** + * This class was created by . 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Sep 6, 2015, 4:03:56 PM (GMT)] + */ +package vazkii.botania.common.block; + +import java.util.ArrayList; + +import net.minecraft.block.material.Material; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import vazkii.botania.common.block.tile.TileCell; +import vazkii.botania.common.lib.LibBlockNames; + +public class BlockCell extends BlockModContainer { + + public BlockCell() { + super(Material.gourd); + setBlockName(LibBlockNames.CELL_BLOCK); + } + + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + return new ArrayList(); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileCell(); + } + +} diff --git a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java index c5dbef1eb..15c3f67a4 100644 --- a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java +++ b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java @@ -70,6 +70,7 @@ public class BlockSpecialFlower extends BlockFlower implements ITileEntityProvid LibBlockNames.SUBTILE_GOURMARYLLIS, LibBlockNames.SUBTILE_NARSLIMMUS, LibBlockNames.SUBTILE_SPECTROLUS, + LibBlockNames.SUBTILE_DANDELIFEON, // Functional LibBlockNames.SUBTILE_JADED_AMARANTHUS, diff --git a/src/main/java/vazkii/botania/common/block/ModBlocks.java b/src/main/java/vazkii/botania/common/block/ModBlocks.java index fd15b727e..24ff42167 100644 --- a/src/main/java/vazkii/botania/common/block/ModBlocks.java +++ b/src/main/java/vazkii/botania/common/block/ModBlocks.java @@ -98,6 +98,7 @@ import vazkii.botania.common.block.subtile.functional.SubTileTangleberrie; import vazkii.botania.common.block.subtile.functional.SubTileTigerseye; import vazkii.botania.common.block.subtile.functional.SubTileVinculotus; import vazkii.botania.common.block.subtile.generating.SubTileArcaneRose; +import vazkii.botania.common.block.subtile.generating.SubTileDandelifeon; import vazkii.botania.common.block.subtile.generating.SubTileDaybloom; import vazkii.botania.common.block.subtile.generating.SubTileEndoflame; import vazkii.botania.common.block.subtile.generating.SubTileEntropinnyum; @@ -114,6 +115,7 @@ import vazkii.botania.common.block.tile.TileAltar; import vazkii.botania.common.block.tile.TileBifrost; import vazkii.botania.common.block.tile.TileBrewery; import vazkii.botania.common.block.tile.TileCacophonium; +import vazkii.botania.common.block.tile.TileCell; import vazkii.botania.common.block.tile.TileCocoon; import vazkii.botania.common.block.tile.TileCraftCrate; import vazkii.botania.common.block.tile.TileEnchanter; @@ -246,6 +248,7 @@ public final class ModBlocks { public static Block cacophonium; public static Block bellows; public static Block bifrostPerm; + public static Block cellBlock; public static void init() { flower = new BlockModFlower(); @@ -329,7 +332,8 @@ public final class ModBlocks { cacophonium = new BlockCacophonium(); bellows = new BlockBellows(); bifrostPerm = new BlockBifrostPerm(); - + cellBlock = new BlockCell(); + ModFluffBlocks.init(); for(int i = 0; i < 16; i++) @@ -425,6 +429,7 @@ public final class ModBlocks { registerTile(TileLightRelay.class, LibBlockNames.LIGHT_RELAY); registerTile(TileCacophonium.class, LibBlockNames.CACOPHONIUM); registerTile(TileBellows.class, LibBlockNames.BELLOWS); + registerTile(TileCell.class, LibBlockNames.CELL_BLOCK); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class); @@ -441,6 +446,7 @@ public final class ModBlocks { BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_GOURMARYLLIS, SubTileGourmaryllis.class); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_NARSLIMMUS, SubTileNarslimmus.class); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_SPECTROLUS, SubTileSpectrolus.class); + BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_DANDELIFEON, SubTileDandelifeon.class); registerSubTileWithMini(LibBlockNames.SUBTILE_BELLETHORN, SubTileBellethorn.class); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_DREADTHORN, SubTileDreadthorn.class); diff --git a/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileDandelifeon.java b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileDandelifeon.java new file mode 100644 index 000000000..335dd4903 --- /dev/null +++ b/src/main/java/vazkii/botania/common/block/subtile/generating/SubTileDandelifeon.java @@ -0,0 +1,189 @@ +/** + * This class was created by . 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Sep 6, 2015, 3:46:10 PM (GMT)] + */ +package vazkii.botania.common.block.subtile.generating; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import vazkii.botania.api.subtile.RadiusDescriptor; +import vazkii.botania.api.subtile.SubTileGenerating; +import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.block.tile.TileCell; + +public class SubTileDandelifeon extends SubTileGenerating { + + private static final int RANGE = 12; + private static final int SPEED = 10; + private static final int MAX_GENERATIONS = 60; + private static final int MANA_PER_GEN = 80; + + private static final int[][] ADJACENT_BLOCKS = new int[][] { + { -1, -1 }, + { -1, +0 }, + { -1, +1 }, + { +0, +1 }, + { +1, +1 }, + { +1, +0 }, + { +1, -1 }, + { +0, -1 } + }; + + @Override + public void onUpdate() { + super.onUpdate(); + + if(!supertile.getWorldObj().isRemote && redstoneSignal > 0 && ticksExisted % SPEED == 0) + runSimulation(); + } + + void runSimulation() { + int[][] table = getCellTable(); + List changes = new ArrayList(); + + for(int i = 0; i < table.length; i++) + for(int j = 0; j < table[0].length; j++) { + int gen = table[i][j]; + int adj = getAdjCells(table, i, j); + + int newVal = gen; + if(adj < 2 || adj > 3) + newVal = -1; + else { + if(adj == 3 && gen == -1) + newVal = getSpawnCellGeneration(table, i, j); + else if(gen > -1) + newVal = gen + 1; + } + + if(Math.abs(i - RANGE) <= 1 && Math.abs(j - RANGE) <= 1 && newVal > -1) { + gen = newVal; + newVal = -2; + } + + if(newVal != gen) + changes.add(new int[] { i, j, newVal, gen }); + } + + int x = supertile.xCoord; + int y = supertile.yCoord; + int z = supertile.zCoord; + + for(int[] change : changes) { + int px = x - RANGE + change[0]; + int pz = z - RANGE + change[1]; + int val = change[2]; + int old = change[3]; + + setBlockForGeneration(px, y, pz, val, old); + } + } + + int[][] getCellTable() { + int diam = RANGE * 2 + 1; + int[][] table = new int[diam][diam]; + + int x = supertile.xCoord; + int y = supertile.yCoord; + int z = supertile.zCoord; + + for(int i = 0; i < diam; i++) + for(int j = 0; j < diam; j++) { + int px = x - RANGE + i; + int pz = z - RANGE + j; + table[i][j] = getCellGeneration(px, y, pz); + } + + return table; + } + + int getCellGeneration(int x, int y, int z) { + TileEntity tile = supertile.getWorldObj().getTileEntity(x, y, z); + if(tile instanceof TileCell) + return ((TileCell) tile).getGeneration(); + + return -1; + } + + int getAdjCells(int[][] table, int x, int z) { + int count = 0; + for(int[] shift : ADJACENT_BLOCKS) { + int xp = x + shift[0]; + int zp = z + shift[1]; + if(!isOffBounds(table, xp, zp)) { + int gen = table[xp][zp]; + if(gen >= 0) + count++; + } + } + + return count; + } + + int getSpawnCellGeneration(int[][] table, int x, int z) { + int max = -1; + for(int[] shift : ADJACENT_BLOCKS) { + int xp = x + shift[0]; + int zp = z + shift[1]; + if(!isOffBounds(table, xp, zp)) { + int gen = table[xp][zp]; + if(gen > max) + max = gen; + } + } + + return max == -1 ? -1 : max + 1; + } + + boolean isOffBounds(int[][] table, int x, int z) { + return x < 0 || z < 0 || x >= table.length || z >= table[0].length; + } + + void setBlockForGeneration(int x, int y, int z, int gen, int prevGen) { + World world = supertile.getWorldObj(); + Block blockAt = world.getBlock(x, y, z); + if(gen == -2) { + int val = prevGen * MANA_PER_GEN; + mana = Math.min(getMaxMana(), mana + val); + world.setBlockToAir(x, y, z); + } else if(blockAt == ModBlocks.cellBlock) { + if(gen < 0 || gen > MAX_GENERATIONS) + world.setBlockToAir(x, y, z); + else ((TileCell) world.getTileEntity(x, y, z)).setGeneration(gen); + } else if(gen >= 0 && blockAt.isAir(supertile.getWorldObj(), x, y, z)) { + world.setBlock(x, y, z, ModBlocks.cellBlock); + ((TileCell) world.getTileEntity(x, y, z)).setGeneration(gen); + } + } + + @Override + public boolean acceptsRedstone() { + return true; + } + + @Override + public RadiusDescriptor getRadius() { + return new RadiusDescriptor.Square(toChunkCoordinates(), RANGE); + } + + @Override + public int getMaxMana() { + return 50000; + } + + @Override + public int getColor() { + return 0x9c0a7e; + } + +} diff --git a/src/main/java/vazkii/botania/common/block/tile/TileCell.java b/src/main/java/vazkii/botania/common/block/tile/TileCell.java new file mode 100644 index 000000000..a9f73fb69 --- /dev/null +++ b/src/main/java/vazkii/botania/common/block/tile/TileCell.java @@ -0,0 +1,44 @@ +/** + * This class was created by . 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Sep 6, 2015, 4:07:16 PM (GMT)] + */ +package vazkii.botania.common.block.tile; + +import net.minecraft.nbt.NBTTagCompound; + +public class TileCell extends TileMod { + + private static final String TAG_GENERATION = "generation"; + + private int generation; + + @Override + public boolean canUpdate() { + return false; + } + + public void setGeneration(int gen) { + generation = gen; + } + + public int getGeneration() { + return generation; + } + + @Override + public void writeCustomNBT(NBTTagCompound cmp) { + cmp.setInteger(TAG_GENERATION, generation); + } + + @Override + public void readCustomNBT(NBTTagCompound cmp) { + generation = cmp.getInteger(TAG_GENERATION); + } + +} diff --git a/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java b/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java index b401ece68..91d6754f7 100644 --- a/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -271,6 +271,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addBlock(ModBlocks.corporeaCrystalCube); addBlock(ModBlocks.lightRelay); addBlock(ModBlocks.lightLauncher); + addBlock(ModBlocks.cellBlock); // FLUFF diff --git a/src/main/java/vazkii/botania/common/lib/LibBlockNames.java b/src/main/java/vazkii/botania/common/lib/LibBlockNames.java index b66a75803..6394bba62 100644 --- a/src/main/java/vazkii/botania/common/lib/LibBlockNames.java +++ b/src/main/java/vazkii/botania/common/lib/LibBlockNames.java @@ -97,6 +97,7 @@ public final class LibBlockNames { public static final String BELLOWS = "bellows"; public static final String BIFROST_PERM = "bifrostPerm"; public static final String PAVEMENT = "pavement"; + public static final String CELL_BLOCK = "cellBlock"; public static final String SUBTILE_PUREDAISY = "puredaisy"; public static final String SUBTILE_MANASTAR = "manastar"; @@ -113,6 +114,7 @@ public final class LibBlockNames { public static final String SUBTILE_GOURMARYLLIS = "gourmaryllis"; public static final String SUBTILE_NARSLIMMUS = "narslimmus"; public static final String SUBTILE_SPECTROLUS = "spectrolus"; + public static final String SUBTILE_DANDELIFEON = "dandelifeon"; public static final String SUBTILE_BELLETHORN = "bellethorn"; public static final String SUBTILE_DREADTHORN = "dreadthorn"; diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index c6df1c93f..5ad47b1e4 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -1038,6 +1038,7 @@ tile.botania:pavement0Slab.name=White Portuguese Pavement Slab tile.botania:pavement1Slab.name=Black Portuguese Pavement Slab tile.botania:pavement2Slab.name=Blue Portuguese Pavement Slab tile.botania:pavement3Slab.name=Red Portuguese Pavement Slab +tile.botania:cellBlock.name=Cellular Block # FLOWER NAMES tile.botania:flower..name=Botania Flower @@ -1075,6 +1076,8 @@ tile.botania:flower.narslimmus.name=Narslimmus tile.botania:flower.narslimmus.reference=What's this? It's all sticky tile.botania:flower.spectrolus.name=Spectrolus tile.botania:flower.spectrolus.reference=Profiting off Hate +tile.botania:flower.dandelifeon.name=Dandelifeon +tile.botania:flower.dandelifeon.reference=C'est la vie # - FUNCTIONAL tile.botania:flower.bellethorn.name=Bellethorne diff --git a/src/main/resources/assets/botania/textures/blocks/cellBlock.png b/src/main/resources/assets/botania/textures/blocks/cellBlock.png new file mode 100644 index 000000000..86ff1eed8 Binary files /dev/null and b/src/main/resources/assets/botania/textures/blocks/cellBlock.png differ diff --git a/src/main/resources/assets/botania/textures/blocks/dandelifeon.png b/src/main/resources/assets/botania/textures/blocks/dandelifeon.png new file mode 100644 index 000000000..08169fc0f Binary files /dev/null and b/src/main/resources/assets/botania/textures/blocks/dandelifeon.png differ diff --git a/src/main/resources/assets/botania/textures/blocks/dandelifeon.png.mcmeta b/src/main/resources/assets/botania/textures/blocks/dandelifeon.png.mcmeta new file mode 100644 index 000000000..8c2ba81fd --- /dev/null +++ b/src/main/resources/assets/botania/textures/blocks/dandelifeon.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation": { + "frametime": 10 + } +} \ No newline at end of file