mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 02:45:13 +00:00
IslandTypes can now be added by addons
This commit is contained in:
1 parent
d3055c4c4d
commit
cbac5fbb32
5 files changed
+82
-51
No files matched your search
@@ -10,9 +10,8 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.decor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -38,13 +37,13 @@ import vazkii.botania.common.block.decor.IFloatingFlower.IslandType;
|
||||
import vazkii.botania.common.block.tile.TileFloatingFlower;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.integration.coloredlights.ColoredLightHelper;
|
||||
import vazkii.botania.common.item.ItemGrassSeeds;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.item.IFloatingFlowerVariant;
|
||||
import vazkii.botania.common.item.block.ItemBlockWithMetadataAndName;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Optional.Interface(modid = "Thaumcraft", iface = "thaumcraft.api.crafting.IInfusionStabiliser", striprefs = true)
|
||||
public class BlockFloatingFlower extends BlockModContainer implements ILexiconable, IInfusionStabiliser {
|
||||
@@ -133,8 +132,8 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
|
||||
IslandType type = null;
|
||||
if(stack.getItem() == Items.snowball)
|
||||
type = IslandType.SNOW;
|
||||
else if(stack.getItem() == ModItems.grassSeeds) {
|
||||
IslandType newType = ItemGrassSeeds.getIslandType(stack);
|
||||
else if(stack.getItem() instanceof IFloatingFlowerVariant) {
|
||||
IslandType newType = ((IFloatingFlowerVariant) stack.getItem()).getIslandType(stack);
|
||||
if(newType != null)
|
||||
type = newType;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface IFloatingFlower {
|
||||
|
||||
public ItemStack getDisplayStack();
|
||||
@@ -22,36 +24,47 @@ public interface IFloatingFlower {
|
||||
|
||||
public void setIslandType(IslandType type);
|
||||
|
||||
public static enum IslandType {
|
||||
GRASS(LibResources.MODEL_MINI_ISLAND),
|
||||
PODZOL(LibResources.MODEL_MINI_ISLAND_PODZOL),
|
||||
MYCEL(LibResources.MODEL_MINI_ISLAND_MYCEL),
|
||||
SNOW(LibResources.MODEL_MINI_ISLAND_SNOW),
|
||||
DRY(LibResources.MODEL_MINI_ISLAND_DRY),
|
||||
GOLDEN(LibResources.MODEL_MINI_ISLAND_GOLDEN),
|
||||
VIVID(LibResources.MODEL_MINI_ISLAND_VIVID),
|
||||
SCORCHED(LibResources.MODEL_MINI_ISLAND_SCORCHED),
|
||||
INFUSED(LibResources.MODEL_MINI_ISLAND_INFUSED),
|
||||
MUTATED(LibResources.MODEL_MINI_ISLAND_MUTATED);
|
||||
public class IslandType {
|
||||
private static HashMap<String, IslandType> registry = new HashMap<String, IslandType>();
|
||||
|
||||
private IslandType(String s) {
|
||||
res = new ResourceLocation(s);
|
||||
public static final IslandType GRASS = new IslandType("GRASS", LibResources.MODEL_MINI_ISLAND);
|
||||
public static final IslandType PODZOL = new IslandType("PODZOL", LibResources.MODEL_MINI_ISLAND_PODZOL);
|
||||
public static final IslandType MYCEL = new IslandType("MYCEL", LibResources.MODEL_MINI_ISLAND_MYCEL);
|
||||
public static final IslandType SNOW = new IslandType("SNOW", LibResources.MODEL_MINI_ISLAND_SNOW);
|
||||
public static final IslandType DRY = new IslandType("DRY", LibResources.MODEL_MINI_ISLAND_DRY);
|
||||
public static final IslandType GOLDEN = new IslandType("GOLDEN", LibResources.MODEL_MINI_ISLAND_GOLDEN);
|
||||
public static final IslandType VIVID = new IslandType("VIVID", LibResources.MODEL_MINI_ISLAND_VIVID);
|
||||
public static final IslandType SCORCHED = new IslandType("SCORCHED", LibResources.MODEL_MINI_ISLAND_SCORCHED);
|
||||
public static final IslandType INFUSED = new IslandType("INFUSED", LibResources.MODEL_MINI_ISLAND_INFUSED);
|
||||
public static final IslandType MUTATED = new IslandType("MUTATED", LibResources.MODEL_MINI_ISLAND_MUTATED);
|
||||
|
||||
public IslandType(String name, String s) {
|
||||
this(name, new ResourceLocation(s));
|
||||
}
|
||||
|
||||
public IslandType(String name, ResourceLocation s) {
|
||||
if (registry.containsKey(name)) throw new IllegalArgumentException(name+" already registered!");
|
||||
this.typeName = name;
|
||||
res = s;
|
||||
registry.put(name, this);
|
||||
}
|
||||
|
||||
private final ResourceLocation res;
|
||||
public final String typeName;
|
||||
|
||||
public static IslandType ofType(String typeStr) {
|
||||
for(IslandType type : IslandType.class.getEnumConstants())
|
||||
if(type.toString().equals(typeStr))
|
||||
return type;
|
||||
|
||||
return GRASS;
|
||||
IslandType type = registry.get(typeStr);
|
||||
return type == null ? GRASS : type;
|
||||
}
|
||||
|
||||
public ResourceLocation getResource() {
|
||||
return res;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.typeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,11 +54,12 @@ public class TileFloatingSpecialFlower extends TileSpecialFlower implements IFlo
|
||||
|
||||
@Override
|
||||
public int getSlowdownFactor() {
|
||||
switch(getIslandType()) {
|
||||
case MYCEL: return SLOWDOWN_FACTOR_MYCEL;
|
||||
case PODZOL: return SLOWDOWN_FACTOR_PODZOL;
|
||||
default: return 0;
|
||||
}
|
||||
IslandType type = getIslandType();
|
||||
if (type == IslandType.MYCEL)
|
||||
return SLOWDOWN_FACTOR_MYCEL;
|
||||
else if (type == IslandType.PODZOL)
|
||||
return SLOWDOWN_FACTOR_PODZOL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* This class was created by <WireSegal>. 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 @ [Jan 13, 2016, 6:02:31 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.common.block.decor.IFloatingFlower.IslandType;
|
||||
|
||||
public interface IFloatingFlowerVariant {
|
||||
public IslandType getIslandType(ItemStack stack);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemGrassSeeds extends ItemMod {
|
||||
public class ItemGrassSeeds extends ItemMod implements IFloatingFlowerVariant {
|
||||
|
||||
private static Map<Integer, List<BlockSwapper>> blockSwappers = new HashMap();
|
||||
|
||||
@@ -170,9 +170,9 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
int dim = event.world.provider.dimensionId;
|
||||
if(blockSwappers.containsKey(dim)) {
|
||||
List<BlockSwapper> swappers = blockSwappers.get(dim);
|
||||
|
||||
|
||||
Iterator<BlockSwapper> iter = swappers.listIterator();
|
||||
|
||||
|
||||
while(iter.hasNext()) {
|
||||
BlockSwapper next = iter.next();
|
||||
if(!next.tick())
|
||||
@@ -209,7 +209,7 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
|
||||
/**
|
||||
* A block swapper for the Pasture Seeds, which swaps dirt and grass blocks
|
||||
* centered around a provided point to a provided block/metadata.
|
||||
* centered around a provided point to a provided block/metadata.
|
||||
*/
|
||||
private static class BlockSwapper {
|
||||
|
||||
@@ -217,12 +217,12 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
* The range of the block swapper, in blocks.
|
||||
*/
|
||||
public static final int RANGE = 3;
|
||||
|
||||
|
||||
/**
|
||||
* The range around which a block can spread in a single tick.
|
||||
*/
|
||||
public static final int TICK_RANGE = 1;
|
||||
|
||||
|
||||
private final World world;
|
||||
private final Random rand;
|
||||
private final Block blockToSet;
|
||||
@@ -270,7 +270,7 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
if(block == blockToSet && meta == metaToSet) {
|
||||
// Only make changes every 20 ticks
|
||||
if(ticksExisted % 20 != 0) continue;
|
||||
|
||||
|
||||
tickBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
// This swapper should exist for 80 ticks
|
||||
return ticksExisted < 80;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tick a specific block position, finding the valid blocks
|
||||
* immediately adjacent to it and then replacing one at random.
|
||||
@@ -289,27 +289,27 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
*/
|
||||
public void tickBlock(int x, int y, int z) {
|
||||
List<ChunkCoordinates> validCoords = new ArrayList<ChunkCoordinates>();
|
||||
|
||||
|
||||
// Go around this block and aggregate valid blocks.
|
||||
for(int xOffset = -TICK_RANGE; xOffset <= TICK_RANGE; xOffset++) {
|
||||
for(int zOffset = -TICK_RANGE; zOffset <= TICK_RANGE; zOffset++) {
|
||||
// Skip the current block
|
||||
if(xOffset == 0 && zOffset == 0) continue;
|
||||
|
||||
|
||||
if(isValidSwapPosition(x + xOffset, y, z + zOffset))
|
||||
validCoords.add(new ChunkCoordinates(x + xOffset, y, z + zOffset));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If we can make changes, and have at least 1 block to swap,
|
||||
// then swap a random block from the valid blocks we could swap.
|
||||
if(!validCoords.isEmpty() && !world.isRemote) {
|
||||
ChunkCoordinates toSwap = validCoords.get(rand.nextInt(validCoords.size()));
|
||||
|
||||
|
||||
world.setBlock(toSwap.posX, toSwap.posY, toSwap.posZ, blockToSet, metaToSet, 1 | 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if a given position is a valid location to spread to, which
|
||||
* means that the block must be either dirt or grass (with meta 0),
|
||||
@@ -322,23 +322,23 @@ public class ItemGrassSeeds extends ItemMod {
|
||||
public boolean isValidSwapPosition(int x, int y, int z) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
|
||||
Block aboveBlock = world.getBlock(x, y + 1, z);
|
||||
|
||||
|
||||
// Valid blocks to spread to are either dirt or grass, and do not
|
||||
// have blocks which block grass growth.
|
||||
|
||||
|
||||
// See http://minecraft.gamepedia.com/Grass_Block
|
||||
// The major rule is that a block which reduces light
|
||||
// levels by 2 or more blocks grass growth.
|
||||
|
||||
return (block == Blocks.dirt || block == Blocks.grass)
|
||||
|
||||
return (block == Blocks.dirt || block == Blocks.grass)
|
||||
&& (meta == 0)
|
||||
&& (aboveBlock.getLightOpacity(world, x, y, z) <= 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static IslandType getIslandType(ItemStack stack) {
|
||||
public IslandType getIslandType(ItemStack stack) {
|
||||
return ISLAND_TYPES[Math.min(stack.getItemDamage(), ISLAND_TYPES.length - 1)];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user