Merge upstream

This commit is contained in:
Vincent Lee committed 2016-01-14 16:40:14 -06:00
commit e12163f70c
26 files changed
+763 -370

No files matched your search

@@ -1,10 +1,14 @@
package vazkii.botania.api;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.subtile.SubTileEntity;
import vazkii.botania.api.item.IFloatingFlower;
import java.util.Collections;
import java.util.Map;
@@ -15,8 +19,9 @@ import java.util.Map;
@SideOnly(Side.CLIENT)
public final class BotaniaAPIClient {
private static final Map<String, ModelResourceLocation> queuedBlockModels = Maps.newHashMap();
private static final Map<String, ModelResourceLocation> queuedItemModels = Maps.newHashMap();
private static final Map<String, ModelResourceLocation> subtileBlockModels = Maps.newHashMap();
private static final Map<String, ModelResourceLocation> subtileItemModels = Maps.newHashMap();
private static final Map<IFloatingFlower.IslandType, ModelResourceLocation> islandTypeModels = Maps.newHashMap();
/**
* Register your model for the given subtile class here.
@@ -29,13 +34,14 @@ public final class BotaniaAPIClient {
* @param itemModel A path to a blockstate json and variant to be used for this subtile's item form
*/
public static void registerSubtileModel(String subTileName, ModelResourceLocation model, ModelResourceLocation itemModel) {
queuedBlockModels.put(subTileName, model);
queuedItemModels.put(subTileName, itemModel);
Preconditions.checkState(Loader.instance().isInState(LoaderState.PREINITIALIZATION));
subtileBlockModels.put(subTileName, model);
subtileItemModels.put(subTileName, itemModel);
}
/**
* Register your model for the given subtile class here.
* Call this DURING PREINIT. Calling it anytime after blockModels have already baked does not guarantee that your model will work.
* Call this DURING PREINIT.
* Your model json must specify key "tintindex" in all the faces it wants tint applied.
* Tint is applied whenever a player recolors the flower using floral dye
*
@@ -56,17 +62,35 @@ public final class BotaniaAPIClient {
}
/**
* @return An immutable view of the registered subtile block model map
* @return An immutable and live view of the registered subtile block model map
*/
public static Map<String, ModelResourceLocation> getRegisteredSubtileBlockModels() {
return Collections.unmodifiableMap(queuedBlockModels);
return Collections.unmodifiableMap(subtileBlockModels);
}
/**
* @return An immutable view of the registered subtile item model map
* @return An immutable and live view of the registered subtile item model map
*/
public static Map<String, ModelResourceLocation> getRegisteredSubtileItemModels() {
return Collections.unmodifiableMap(queuedItemModels);
return Collections.unmodifiableMap(subtileItemModels);
}
/**
* Registers your model for island type islandType here.
* Call this DURING PREINIT.
* @param islandType The islandtype to register
* @param model The variant within a blockstate json to use as the islandtype's model
*/
public static void registerIslandTypeModel(IFloatingFlower.IslandType islandType, ModelResourceLocation model) {
Preconditions.checkState(Loader.instance().isInState(LoaderState.PREINITIALIZATION));
islandTypeModels.put(islandType, model);
}
/**
* @return An immutable and live view of the registered island type model map
*/
public static Map<IFloatingFlower.IslandType, ModelResourceLocation> getRegisteredIslandTypeModels() {
return Collections.unmodifiableMap(islandTypeModels);
}
private BotaniaAPIClient() {}
@@ -0,0 +1,63 @@
/**
* 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 the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Nov 17, 2014, 6:05:18 PM (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.item.ItemStack;
import java.util.HashMap;
public interface IFloatingFlower {
public ItemStack getDisplayStack();
public IslandType getIslandType();
public void setIslandType(IslandType type);
public class IslandType {
private static HashMap<String, IslandType> registry = new HashMap<String, IslandType>();
public static final IslandType GRASS = new IslandType("GRASS");
public static final IslandType PODZOL = new IslandType("PODZOL");
public static final IslandType MYCEL = new IslandType("MYCEL");
public static final IslandType SNOW = new IslandType("SNOW");
public static final IslandType DRY = new IslandType("DRY");
public static final IslandType GOLDEN = new IslandType("GOLDEN");
public static final IslandType VIVID = new IslandType("VIVID");
public static final IslandType SCORCHED = new IslandType("SCORCHED");
public static final IslandType INFUSED = new IslandType("INFUSED");
public static final IslandType MUTATED = new IslandType("MUTATED");
/**
* Instantiates and registers a new floating flower island type
* Note that you need to register the model for this island type, see BotaniaAPIClient
* @param name The name of this floating flower island type
*/
public IslandType(String name) {
if (registry.containsKey(name)) throw new IllegalArgumentException(name+" already registered!");
this.typeName = name;
registry.put(name, this);
}
public final String typeName;
public static IslandType ofType(String typeStr) {
IslandType type = registry.get(typeStr);
return type == null ? GRASS : type;
}
@Override
public String toString() {
return this.typeName;
}
}
}
@@ -8,7 +8,6 @@
*/
package vazkii.botania.api.state;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.BlockRailPowered;
@@ -16,8 +15,10 @@ import net.minecraft.block.BlockRotatedPillar;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.EnumFacing;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.api.state.enums.*;
/**
@@ -28,10 +29,13 @@ public class BotaniaStateProps {
/** Unlisted properties **/
// The property for specialFlower subtile id
public static final PropertyString SUBTILE_ID = new PropertyString("subtile_id");
public static final PropertyObject<String> SUBTILE_ID = new PropertyObject<>("subtile_id", String.class);
// The property for floating flower island type
public static final PropertyObject<IFloatingFlower.IslandType> ISLAND_TYPE = new PropertyObject<>("islandtype", IFloatingFlower.IslandType.class);
// The property for platform held blockstate id
public static final PropertyState HELD_STATE = new PropertyState("held_state");
public static final PropertyObject<IBlockState> HELD_STATE = new PropertyObject<>("held_state", IBlockState.class);
/** Common properties to all blocks to use **/
@@ -0,0 +1,46 @@
package vazkii.botania.api.state;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.minecraftforge.common.property.IUnlistedProperty;
// Generic base class for unlisted properties
public class PropertyObject<T> implements IUnlistedProperty<T> {
private final String name;
private final Class<T> clazz;
private final Predicate<T> validator;
private final Function<T, String> stringFunction;
public PropertyObject(String name, Class<T> clazz, Predicate<T> validator, Function<T, String> stringFunction) {
this.name = name;
this.clazz = clazz;
this.validator = validator;
this.stringFunction = stringFunction;
}
public PropertyObject(String name, Class<T> clazz) {
this(name, clazz, Predicates.alwaysTrue(), Object::toString);
}
@Override
public String getName() {
return name;
}
@Override
public boolean isValid(T value) {
return validator.apply(value);
}
@Override
public Class<T> getType() {
return clazz;
}
@Override
public String valueToString(T value) {
return stringFunction.apply(value);
}
}
@@ -1,43 +0,0 @@
/**
* This class was created by <williewillus>. 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
*/
package vazkii.botania.api.state;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
// An unlisted property that holds an IBlockState. Used for platform rendering
public class PropertyState implements IUnlistedProperty<IBlockState> {
private final String name;
public PropertyState(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public boolean isValid(IBlockState value) {
return true;
}
@Override
public Class<IBlockState> getType() {
return IBlockState.class;
}
@Override
public String valueToString(IBlockState value) {
return value.toString();
}
}
@@ -1,41 +0,0 @@
/**
* This class was created by <williewillus>. 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
*/
package vazkii.botania.api.state;
import net.minecraftforge.common.property.IUnlistedProperty;
// An unlisted property that holds a String, used for subtile rendering
public class PropertyString implements IUnlistedProperty<String> {
private final String name;
public PropertyString(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public boolean isValid(String value) {
return true;
}
@Override
public Class<String> getType() {
return String.class;
}
@Override
public String valueToString(String value) {
return value;
}
}
@@ -34,6 +34,7 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.fml.common.registry.GameData;
import vazkii.botania.api.BotaniaAPIClient;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.api.state.enums.PlatformVariant;
import vazkii.botania.api.state.enums.SpreaderVariant;
import vazkii.botania.client.model.SpecialFlowerModel;
@@ -287,6 +288,17 @@ public final class ModelHandler {
}
private static void registerSubtiles() {
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GRASS, new ModelResourceLocation("botania:miniIsland", "variant=grass"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.PODZOL, new ModelResourceLocation("botania:miniIsland", "variant=podzol"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MYCEL, new ModelResourceLocation("botania:miniIsland", "variant=mycel"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SNOW, new ModelResourceLocation("botania:miniIsland", "variant=snow"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.DRY, new ModelResourceLocation("botania:miniIsland", "variant=dry"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.GOLDEN, new ModelResourceLocation("botania:miniIsland", "variant=golden"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.VIVID, new ModelResourceLocation("botania:miniIsland", "variant=vivid"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.SCORCHED, new ModelResourceLocation("botania:miniIsland", "variant=scorched"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.INFUSED, new ModelResourceLocation("botania:miniIsland", "variant=infused"));
BotaniaAPIClient.registerIslandTypeModel(IFloatingFlower.IslandType.MUTATED, new ModelResourceLocation("botania:miniIsland", "variant=mutated"));
BotaniaAPIClient.registerSubtileModel(SubTileManastar.class, new ModelResourceLocation("botania:" + LibBlockNames.SUBTILE_MANASTAR));
BotaniaAPIClient.registerSubtileModel(SubTilePureDaisy.class, new ModelResourceLocation("botania:" + LibBlockNames.SUBTILE_PUREDAISY));
@@ -8,10 +8,8 @@
*/
package vazkii.botania.client.model;
import com.google.common.base.Function;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Table;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -35,10 +33,12 @@ import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.client.model.pipeline.VertexTransformer;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.common.FMLLog;
import vazkii.botania.api.BotaniaAPIClient;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.decor.BlockFloatingFlower;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.common.item.block.ItemBlockFloatingSpecialFlower;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
@@ -79,12 +79,12 @@ public class FloatingFlowerModel implements ISmartItemModel, ISmartBlockModel, I
@Override
public IBakedModel handleBlockState(IBlockState state) {
IFloatingFlower.IslandType islandType = state.getValue(BlockFloatingFlower.ISLAND_TYPE);
IExtendedBlockState realState = ((IExtendedBlockState) state);
IFloatingFlower.IslandType islandType = realState.getValue(BotaniaStateProps.ISLAND_TYPE);
String identifier;
if (state.getBlock() == ModBlocks.floatingSpecialFlower) {
// Magic flower
IExtendedBlockState realState = ((IExtendedBlockState) state);
identifier = realState.getValue(BotaniaStateProps.SUBTILE_ID);
} else {
// Mundane flower
@@ -101,7 +101,7 @@ public class FloatingFlowerModel implements ISmartItemModel, ISmartBlockModel, I
if (CACHE.contains(islandType, identifier)) {
return CACHE.get(islandType, identifier);
} else {
IBakedModel islandModel = modelManager.getModel(new ModelResourceLocation("botania:miniIsland", "variant=" + islandType.getName()));
IBakedModel islandModel = modelManager.getModel(BotaniaAPIClient.getRegisteredIslandTypeModels().get(islandType));
IBakedModel flowerModel;
if (identifier.startsWith(MUNDANE_PREFIX)) {
@@ -113,6 +113,7 @@ public class FloatingFlowerModel implements ISmartItemModel, ISmartBlockModel, I
// Enhance!
CompositeBakedModel model = new CompositeBakedModel(flowerModel, islandModel);
FMLLog.info("[Botania]: Cached floating flower model for islandtpye %s and flowertype %s", islandType, identifier);
CACHE.put(islandType, identifier, model);
return model;
}
@@ -42,7 +42,7 @@ import net.minecraftforge.fml.common.FMLLog;
import org.apache.commons.lang3.tuple.Pair;
import vazkii.botania.api.BotaniaAPIClient;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import javax.vecmath.Matrix4f;
@@ -72,10 +72,8 @@ public class SpecialFlowerModel implements IModelCustomData {
builder.addAll(blockModels.values());
builder.addAll(itemModels.values());
// Force mini island model to be loaded and baked, for use elsewhere. See FloatingFlowerModel
for (IFloatingFlower.IslandType i : IFloatingFlower.IslandType.values()) {
builder.add(new ModelResourceLocation("botania:miniIsland", "variant=" + i.name().toLowerCase(Locale.ROOT)));
}
// Force island models to be loaded and baked. See FloatingFlowerModel.
builder.addAll(BotaniaAPIClient.getRegisteredIslandTypeModels().values());
return builder.build();
}
@@ -24,7 +24,7 @@ import net.minecraft.tileentity.TileEntity;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.model.FloatingFlowerModel;
import vazkii.botania.client.model.ModelMiniIsland;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
public class RenderTileFloatingFlower extends TileEntitySpecialRenderer {
@@ -44,7 +44,7 @@ import vazkii.botania.api.subtile.ISpecialFlower;
import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.decor.BlockFloatingFlower;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.common.block.tile.TileFloatingSpecialFlower;
import vazkii.botania.common.block.tile.TileSpecialFlower;
import vazkii.botania.common.crafting.recipe.SpecialFloatingFlowerRecipe;
@@ -62,19 +62,19 @@ public class BlockFloatingSpecialFlower extends BlockFloatingFlower implements I
GameRegistry.addRecipe(new SpecialFloatingFlowerRecipe());
RecipeSorter.register("botania:floatingSpecialFlower", SpecialFloatingFlowerRecipe.class, Category.SHAPELESS, "");
setDefaultState(((IExtendedBlockState) blockState.getBaseState())
.withProperty(BotaniaStateProps.ISLAND_TYPE, IFloatingFlower.IslandType.GRASS)
.withProperty(BotaniaStateProps.SUBTILE_ID, "daybloom")
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE)
.withProperty(ISLAND_TYPE, IFloatingFlower.IslandType.GRASS));
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE));
}
@Override
public BlockState createBlockState() {
return new ExtendedBlockState(this, new IProperty[] { ISLAND_TYPE, BotaniaStateProps.COLOR }, new IUnlistedProperty[] { BotaniaStateProps.SUBTILE_ID });
return new ExtendedBlockState(this, new IProperty[] { BotaniaStateProps.COLOR }, new IUnlistedProperty[] { BotaniaStateProps.SUBTILE_ID, BotaniaStateProps.ISLAND_TYPE });
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
state = getActualState(state, world, pos);
state = super.getExtendedState(state, world, pos);
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFloatingSpecialFlower) {
state = ((IExtendedBlockState) state).withProperty(BotaniaStateProps.SUBTILE_ID, ((TileFloatingSpecialFlower) te).subTileName);
@@ -10,12 +10,9 @@
*/
package vazkii.botania.common.block.decor;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.EffectRenderer;
@@ -35,35 +32,37 @@ import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import thaumcraft.api.crafting.IInfusionStabiliser;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.BlockModContainer;
import vazkii.botania.common.block.decor.IFloatingFlower.IslandType;
import vazkii.botania.api.item.IFloatingFlower.IslandType;
import vazkii.botania.common.block.tile.TileFloatingFlower;
import vazkii.botania.common.block.tile.TileFloatingSpecialFlower;
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 net.minecraftforge.fml.common.Optional;
import net.minecraftforge.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 {
// Island type (floating flowers)
// Not in BotaniaStateProps so we don't have to bundle IslandType in the API
public static final PropertyEnum<IslandType> ISLAND_TYPE = PropertyEnum.create("islandtype", IFloatingFlower.IslandType.class);
public BlockFloatingFlower() {
this(LibBlockNames.MINI_ISLAND);
}
@@ -77,9 +76,9 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
float f = 0.1F;
setBlockBounds(f, f, f, 1F - f, 1F - f, 1F - f);
setDefaultState(blockState.getBaseState()
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE)
.withProperty(ISLAND_TYPE, IFloatingFlower.IslandType.GRASS));
setDefaultState(((IExtendedBlockState) blockState.getBaseState())
.withProperty(BotaniaStateProps.ISLAND_TYPE, IslandType.GRASS)
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE));
}
@Override
@@ -89,7 +88,7 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
@Override
public BlockState createBlockState() {
return new BlockState(this, BotaniaStateProps.COLOR, ISLAND_TYPE);
return new ExtendedBlockState(this, new IProperty[] { BotaniaStateProps.COLOR }, new IUnlistedProperty[] { BotaniaStateProps.ISLAND_TYPE });
}
@Override
@@ -106,12 +105,13 @@ public class BlockFloatingFlower extends BlockModContainer implements ILexiconab
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
state = getActualState(state, world, pos);
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFloatingFlower) {
state = state.withProperty(ISLAND_TYPE, ((TileFloatingFlower) te).getIslandType());
state = ((IExtendedBlockState) state).withProperty(BotaniaStateProps.ISLAND_TYPE, ((TileFloatingFlower) te).getIslandType());
} else if (te instanceof TileFloatingSpecialFlower) {
state = state.withProperty(ISLAND_TYPE, ((TileFloatingSpecialFlower) te).getIslandType());
state = ((IExtendedBlockState) state).withProperty(BotaniaStateProps.ISLAND_TYPE, ((TileFloatingSpecialFlower) te).getIslandType());
}
return state;
}
@@ -211,8 +211,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;
}
@@ -1,65 +0,0 @@
/**
* 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 the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Nov 17, 2014, 6:05:18 PM (GMT)]
*/
package vazkii.botania.common.block.decor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.client.lib.LibResources;
import java.util.Locale;
public interface IFloatingFlower {
public ItemStack getDisplayStack();
public IslandType getIslandType();
public void setIslandType(IslandType type);
public static enum IslandType implements IStringSerializable {
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);
private IslandType(String s) {
res = new ResourceLocation(s);
}
private final ResourceLocation res;
public static IslandType ofType(String typeStr) {
for(IslandType type : IslandType.class.getEnumConstants())
if(type.toString().equals(typeStr))
return type;
return GRASS;
}
public ResourceLocation getResource() {
return res;
}
@Override
public String getName() {
return name().toLowerCase(Locale.ROOT);
}
}
}
@@ -40,7 +40,7 @@ import vazkii.botania.api.subtile.ISubTileContainer;
import vazkii.botania.api.subtile.RadiusDescriptor;
import vazkii.botania.api.subtile.SubTileEntity;
import vazkii.botania.api.subtile.SubTileFunctional;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import vazkii.botania.common.lexicon.LexiconData;
@@ -102,7 +102,7 @@ public class TileAltar extends TileSimpleInventory implements ISidedInventory, I
boolean didChange = false;
if(stack.getItem() instanceof IFlowerComponent) {
if(stack.getItem() instanceof IFlowerComponent && ((IFlowerComponent) stack.getItem()).canFit(stack, this)) {
if(getStackInSlot(getSizeInventory() - 1) != null)
return false;
@@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
public class TileFloatingFlower extends TileMod implements IFloatingFlower {
@@ -12,7 +12,7 @@ package vazkii.botania.common.block.tile;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.common.block.decor.IFloatingFlower;
import vazkii.botania.api.item.IFloatingFlower;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
public class TileFloatingSpecialFlower extends TileSpecialFlower implements IFloatingFlower {
@@ -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.api.item.IFloatingFlower.IslandType;
public interface IFloatingFlowerVariant {
public IslandType getIslandType(ItemStack stack);
}
@@ -2,10 +2,10 @@
* 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 the
* Botania License: http://botaniamod.net/license.php
*
*
* File Created @ [Sep 23, 2015, 11:40:51 PM (GMT)]
*/
package vazkii.botania.common.item;
@@ -31,9 +31,7 @@ public class ItemGaiaHead extends ItemMod {
setUnlocalizedName(LibItemNames.GAIA_HEAD);
}
// Copypasta from ItemSkull and I'm not even going to bother to clean it up
//
// Deal with it.
// Copied from vanila skull itemBlock. Relevant edits are indicated.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
@@ -123,6 +121,7 @@ public class ItemGaiaHead extends ItemMod {
return true;
}
}
}
@@ -12,6 +12,7 @@ package vazkii.botania.common.item;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -32,13 +33,13 @@ import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.api.state.enums.AltGrassVariant;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.decor.IFloatingFlower.IslandType;
import vazkii.botania.api.item.IFloatingFlower.IslandType;
import vazkii.botania.common.lib.LibItemNames;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
public class ItemGrassSeeds extends ItemMod {
public class ItemGrassSeeds extends ItemMod implements IFloatingFlowerVariant {
private static Map<Integer, List<BlockSwapper>> blockSwappers = new HashMap();
@@ -153,10 +154,14 @@ public class ItemGrassSeeds extends ItemMod {
int dim = event.world.provider.getDimensionId();
if(blockSwappers.containsKey(dim)) {
List<BlockSwapper> swappers = blockSwappers.get(dim);
List<BlockSwapper> swappersSafe = new ArrayList(swappers);
for(BlockSwapper s : swappersSafe)
s.tick(swappers);
Iterator<BlockSwapper> iter = swappers.listIterator();
while(iter.hasNext()) {
BlockSwapper next = iter.next();
if(!next.tick())
iter.remove();
}
}
}
}
@@ -186,58 +191,128 @@ 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.
*/
private static class BlockSwapper {
/**
* The range of the block swapper, in blocks.
*/
public static final int RANGE = 3;
final World world;
final Random rand;
final IBlockState stateToSet;
BlockPos startCoords;
int ticksExisted = 0;
/**
* The range around which a block can spread in a single tick.
*/
public static final int TICK_RANGE = 1;
BlockSwapper(World world, BlockPos coords, IBlockState state) {
private final World world;
private final Random rand;
private final IBlockState stateToSet;
private BlockPos startCoords;
private int ticksExisted = 0;
/**
* Constructs a new block swapper with the provided world, starting
* coordinates, target block, and target metadata.
* @param world The world to swap blocks in.
* @param coords The central coordinates to swap blocks around.
* @param state The target blockstate to swap dirt and grass to.
*/
public BlockSwapper(World world, BlockPos coords, IBlockState state) {
this.world = world;
stateToSet = state;
rand = new Random(coords.hashCode());
startCoords = coords;
this.stateToSet = state;
this.rand = new Random(coords.hashCode());
this.startCoords = coords;
}
void tick(List<BlockSwapper> list) {
/**
* Ticks this block swapper, allowing it to make an action during
* this game tick. This method should return "false" when the swapper
* has finished operation and should be removed from the world.
* @return true if the swapper should continue to exist, false if it
* should be removed.
*/
public boolean tick() {
++ticksExisted;
int range = 3;
for(int i = -range; i < range + 1; i++)
for(int j = -range; j < range + 1; j++) {
// Go through all blocks in the specified RANGE, and then
// try and spread around that block if it is our target block already
for(int i = -RANGE; i <= RANGE; i++) {
for(int j = -RANGE; j <= RANGE; j++) {
BlockPos pos = startCoords.add(i, 0, j);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(state == stateToSet) {
if(ticksExisted % 20 == 0) {
List<BlockPos> validCoords = new ArrayList();
for(int k = -1; k < 2; k++)
for(int l = -1; l < 2; l++) {
BlockPos pos1 = pos.add(k, 0, l);
IBlockState state1 = world.getBlockState(pos1);
if((state1.getBlock() == Blocks.dirt
&& state1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT)
|| state1.getBlock() == Blocks.grass)
validCoords.add(pos1);
}
// Only make changes every 20 ticks
if(ticksExisted % 20 != 0) continue;
if(!validCoords.isEmpty() && !world.isRemote) {
BlockPos coords = validCoords.get(rand.nextInt(validCoords.size()));
world.setBlockState(coords, stateToSet, 1 | 2);
}
}
tickBlock(pos);
}
}
}
if(ticksExisted >= 80)
list.remove(this);
// 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.
* @param pos The positions to use.
*/
public void tickBlock(BlockPos pos) {
List<BlockPos> validCoords = new ArrayList<BlockPos>();
// 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(pos.add(xOffset, 0, zOffset)))
validCoords.add(pos.add(xOffset, 0, 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) {
BlockPos toSwap = validCoords.get(rand.nextInt(validCoords.size()));
world.setBlockState(toSwap, stateToSet, 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),
* and have a block above it which does not block grass growth.
* @param pos The position to check.
* @return True if the position is valid to swap, false otherwise.
*/
public boolean isValidSwapPosition(BlockPos pos) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
Block aboveBlock = world.getBlockState(pos.up()).getBlock();
// 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)
&& (block != Blocks.dirt || state.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT)
&& (aboveBlock.getLightOpacity(world, pos.up()) <= 1);
}
}
public static IslandType getIslandType(ItemStack stack) {
public IslandType getIslandType(ItemStack stack) {
return ISLAND_TYPES[Math.min(stack.getItemDamage(), ISLAND_TYPES.length - 1)];
}
@@ -196,7 +196,7 @@ public class ItemBaubleCosmetic extends ItemBauble implements ICosmeticBauble {
break;
case 26:
faceTranslate();
GlStateManager.translate(-0.1F, -0.5F, 0F);
GlStateManager.translate(-0.1F, -0.4F, 0F);
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1F, 1F, 1F, 0.7F);
@@ -205,7 +205,7 @@ public class ItemBaubleCosmetic extends ItemBauble implements ICosmeticBauble {
case 27:
faceTranslate();
scale(0.75F);
GlStateManager.translate(0.04F, -0.5F, 0F);
GlStateManager.translate(0.04F, -0.65F, 0F);
renderIcon(27);
break;
case 28:
@@ -55,9 +55,6 @@ public class ItemSpeedUpBelt extends ItemTravelBelt {
}
public boolean commitPositionAndCompare(ItemStack stack, EntityPlayer player) {
if(player.worldObj.isRemote)
return true;
double oldX = ItemNBTHelper.getDouble(stack, TAG_OLD_X, 0);
double oldY = ItemNBTHelper.getDouble(stack, TAG_OLD_Y, 0);
double oldZ = ItemNBTHelper.getDouble(stack, TAG_OLD_Z, 0);
@@ -38,7 +38,7 @@ public final class ToolCommons {
public static Material[] materialsPick = new Material[]{ Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil };
public static Material[] materialsShovel = new Material[]{ Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay };
public static Material[] materialsAxe = new Material[]{ Material.coral, Material.leaves, Material.plants, Material.wood };
public static Material[] materialsAxe = new Material[]{ Material.coral, Material.leaves, Material.plants, Material.wood, Material.gourd };
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
int manaToRequest = dmg * manaPerDamage;
@@ -12,8 +12,12 @@ package vazkii.botania.common.item.equipment.tool.terrasteel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
@@ -37,9 +41,32 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
public class ItemTerraAxe extends ItemManasteelAxe implements ISequentialBreaker {
/**
* The number of blocks per tick which the Terra Truncator will
* collect.
*/
public static final int BLOCK_SWAP_RATE = 10;
/**
* The maximum radius (in blocks) which the Terra Truncator will go
* in order to try and murder/cut down the tree.
*/
public static final int BLOCK_RANGE = 32;
/**
* The maximum number of leaf blocks which the Terra Truncator will chew/go
* through once a leaf block is encountered.
*/
public static final int LEAF_BLOCK_RANGE = 3;
/**
* The amount of mana required to restore 1 point of damage.
*/
private static final int MANA_PER_DAMAGE = 100;
private static Map<Integer, List<BlockSwapper>> blockSwappers = new HashMap();
private static Map<Integer, List<BlockSwapper>> blockSwappers = new HashMap<Integer, List<BlockSwapper>>();
public ItemTerraAxe() {
super(BotaniaAPI.terrasteelToolMaterial, LibItemNames.TERRA_AXE);
@@ -69,8 +96,7 @@ public class ItemTerraAxe extends ItemManasteelAxe implements ISequentialBreaker
@Override
public void breakOtherBlock(EntityPlayer player, ItemStack stack, BlockPos pos, BlockPos originPos, EnumFacing side) {
if(shouldBreak(player)) {
BlockPos coords = new BlockPos(pos);
addBlockSwapper(player.worldObj, player, stack, coords, coords, 32, false, true, new ArrayList());
addBlockSwapper(player.worldObj, player, stack, pos, 32, true);
}
}
@@ -85,82 +111,248 @@ public class ItemTerraAxe extends ItemManasteelAxe implements ISequentialBreaker
int dim = event.world.provider.getDimensionId();
if(blockSwappers.containsKey(dim)) {
List<BlockSwapper> swappers = blockSwappers.get(dim);
List<BlockSwapper> swappersSafe = new ArrayList(swappers);
swappers.clear();
for(BlockSwapper s : swappersSafe)
if(s != null)
s.tick();
// Iterate through all of our swappers, removing any
// which no longer need to tick.
Iterator<BlockSwapper> swapper = swappers.iterator();
while(swapper.hasNext()) {
BlockSwapper next = swapper.next();
if(!next.tick())
swapper.remove();
}
}
}
}
private static BlockSwapper addBlockSwapper(World world, EntityPlayer player, ItemStack stack, BlockPos origCoords, BlockPos coords, int steps, boolean leaves, boolean force, List<String> posChecked) {
BlockSwapper swapper = new BlockSwapper(world, player, stack, origCoords, coords, steps, leaves, force, posChecked);
private static BlockSwapper addBlockSwapper(World world, EntityPlayer player, ItemStack stack, BlockPos origCoords, int steps, boolean leaves) {
BlockSwapper swapper = new BlockSwapper(world, player, stack, origCoords, steps, leaves);
int dim = world.provider.getDimensionId();
if(!blockSwappers.containsKey(dim))
blockSwappers.put(dim, new ArrayList());
blockSwappers.put(dim, new ArrayList<BlockSwapper>());
blockSwappers.get(dim).add(swapper);
return swapper;
}
/**
* A block swapper for the Terra Truncator, which uses a standard
* Breadth First Search to try and murder/cut down trees.
*
* The Terra Truncator will look up to BLOCK_RANGE blocks to find wood
* to cut down (only cutting down adjacent pieces of wood, so it doesn't
* jump through the air). However, the truncator will only go through
* LEAF_BLOCK_RANGE leave blocks in order to prevent adjacent trees which
* are connected only by leaves from being devoured as well.
*
* The leaf restriction is implemented by reducing the number of remaining
* steps to the min of LEAF_BLOCK_RANGE and the current range. The restriction
* can be removed entirely by setting the "leaves" variable to true, in which
* case leaves will be treated normally.
*/
private static class BlockSwapper {
final World world;
final EntityPlayer player;
final ItemStack stack;
final BlockPos origCoords;
final int steps;
final BlockPos coords;
final boolean leaves;
final boolean force;
final List<String> posChecked;
BlockSwapper(World world, EntityPlayer player, ItemStack stack, BlockPos origCoords, BlockPos coords, int steps, boolean leaves, boolean force, List<String> posChecked) {
/**
* Represents the range which a single block will scan when looking
* for the next candidates for swapping. 1 is a good default.
*/
public static final int SINGLE_BLOCK_RADIUS = 1;
/**
* The world the block swapper is doing the swapping in.
*/
private final World world;
/**
* The player the swapper is swapping for.
*/
private final EntityPlayer player;
/**
* The Terra Truncator which created this swapper.
*/
private final ItemStack truncator;
/**
* The origin of the swapper (eg, where it started).
*/
private final BlockPos origin;
/**
* Denotes whether leaves should be treated specially.
*/
private final boolean treatLeavesSpecial;
/**
* The initial range which this block swapper starts with.
*/
private final int range;
/**
* The priority queue of all possible candidates for swapping.
*/
private PriorityQueue<SwapCandidate> candidateQueue;
/**
* The set of already swaps coordinates which do not have
* to be revisited.
*/
private Set<BlockPos> completedCoords;
/**
* Creates a new block swapper with the provided parameters.
* @param world The world the swapper is in.
* @param player The player responsible for creating this swapper.
* @param truncator The Terra Truncator responsible for creating this swapper.
* @param origCoords The original coordinates this swapper should start at.
* @param range The range this swapper should swap in.
* @param leaves If true, leaves will be treated specially and
* severely reduce the radius of further spreading when encountered.
*/
public BlockSwapper(World world, EntityPlayer player, ItemStack truncator, BlockPos origCoords, int range, boolean leaves) {
this.world = world;
this.player = player;
this.stack = stack;
this.origCoords = origCoords;
this.coords = coords;
this.steps = steps;
this.leaves = leaves;
this.force = force;
this.posChecked = posChecked;
this.truncator = truncator;
this.origin = origCoords;
this.range = range;
this.treatLeavesSpecial = leaves;
this.candidateQueue = new PriorityQueue<SwapCandidate>();
this.completedCoords = new HashSet<BlockPos>();
// Add the origin to our candidate queue with the original range
candidateQueue.offer(new SwapCandidate(this.origin, this.range));
}
void tick() {
Block blockat = world.getBlockState(coords).getBlock();
if(!force && blockat.isAir(world, coords))
return;
ToolCommons.removeBlockWithDrops(player, stack, world, coords, origCoords, null, ToolCommons.materialsAxe, EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack), 0F, false, !leaves);
if(steps == 0)
return;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++) {
BlockPos pos = coords.add(i - 1, j - 1, k - 1);
String pstr = posStr(pos);
if(posChecked.contains(pstr))
/**
* Ticks this Block Swapper, which allows it to swap BLOCK_SWAP_RATE
* further blocks and expands the breadth first search. The return
* value signifies whether or not the block swapper has more blocks
* to swap, or if it has finished swapping.
* @return True if the block swapper has more blocks to swap, false
* otherwise (implying it can be safely removed).
*/
public boolean tick() {
// If empty, this swapper is done.
if(candidateQueue.isEmpty())
return false;
int remainingSwaps = BLOCK_SWAP_RATE;
while(remainingSwaps > 0 && !candidateQueue.isEmpty()) {
SwapCandidate cand = candidateQueue.poll();
// If we've already completed this location, move along, as this
// is just a suboptimal one.
if(completedCoords.contains(cand.coordinates))
continue;
// If this candidate is out of range, discard it.
if(cand.range <= 0)
continue;
// Otherwise, perform the break and then look at the adjacent tiles.
// This is a ridiculous function call here.
ToolCommons.removeBlockWithDrops(player, truncator, world,
cand.coordinates,
origin,
null, ToolCommons.materialsAxe,
EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, truncator) > 0,
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, truncator),
0F, false, treatLeavesSpecial);
remainingSwaps--;
completedCoords.add(cand.coordinates);
// Then, go through all of the adjacent blocks and look if
// any of them are any good.
for(BlockPos adj : adjacent(cand.coordinates)) {
Block block = world.getBlockState(adj).getBlock();
boolean isWood = block.isWood(world, adj);
boolean isLeaf = block.isLeaves(world, adj);
// If it's not wood or a leaf, we aren't interested.
if(!isWood && !isLeaf)
continue;
// If we treat leaves specially and this is a leaf, it gets
// the minimum of the leaf range and the current range - 1.
// Otherwise, it gets the standard range - 1.
int newRange = treatLeavesSpecial && isLeaf ?
Math.min(LEAF_BLOCK_RANGE, cand.range - 1) :
cand.range - 1;
candidateQueue.offer(new SwapCandidate(adj, newRange));
}
}
// If we did any iteration, then hang around until next tick.
return true;
}
public List<BlockPos> adjacent(BlockPos original) {
List<BlockPos> coords = new ArrayList<BlockPos>();
// Visit all the surrounding blocks in the provided radius.
// Gotta love these nested loops, right?
for(int dx = -SINGLE_BLOCK_RADIUS; dx <= SINGLE_BLOCK_RADIUS; dx++)
for(int dy = -SINGLE_BLOCK_RADIUS; dy <= SINGLE_BLOCK_RADIUS; dy++)
for(int dz = -SINGLE_BLOCK_RADIUS; dz <= SINGLE_BLOCK_RADIUS; dz++) {
// Skip the central tile.
if(dx == 0 && dy == 0 && dz == 0)
continue;
Block block = world.getBlockState(pos).getBlock();
boolean log = block.isWood(world, pos);
boolean leaf = block.isLeaves(world, pos);
if(log || leaf) {
int steps = this.steps - 1;
steps = leaf ? leaves ? steps : 3 : steps;
addBlockSwapper(world, player, stack, origCoords, pos, steps, leaf, false, posChecked);
posChecked.add(pstr);
}
coords.add(original.add(dx, dy, dz));
}
return coords;
}
String posStr(BlockPos pos) {
return pos.getX() + ":" + pos.getY() + ":" + pos.getZ();
/**
* Represents a potential candidate for swapping/removal. Sorted by
* range (where a larger range is more preferable). As we're using
* a priority queue, which is a min-heap internally, larger ranges
* are considered "smaller" than smaller ranges (so they show up in the
* min-heap first).
*/
public static final class SwapCandidate implements Comparable<SwapCandidate> {
/**
* The location of this swap candidate.
*/
public BlockPos coordinates;
/**
* The remaining range of this swap candidate.
*/
public int range;
/**
* Constructs a new Swap Candidate with the provided
* coordinates and range.
* @param coordinates The coordinates of this candidate.
* @param range The remaining range of this candidate.
*/
public SwapCandidate(BlockPos coordinates, int range) {
this.coordinates = coordinates;
this.range = range;
}
@Override
public int compareTo(SwapCandidate other) {
// Aka, a bigger range implies a smaller value, meaning
// bigger ranges will be preferred in a min-heap
return other.range - range;
}
@Override
public boolean equals(Object other) {
if(!(other instanceof SwapCandidate)) return false;
SwapCandidate cand = (SwapCandidate) other;
return coordinates.equals(cand.coordinates) && range == cand.range;
}
}
}
@@ -32,6 +32,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.item.IBlockProvider;
import vazkii.botania.api.item.IManaProficiencyArmor;
import vazkii.botania.api.item.IWireframeCoordinateListProvider;
@@ -152,49 +153,55 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
}
}
public Boolean[][][] createMatrix(World world, ItemStack stack, IBlockState swapState, BlockPos pos, IBlockState targetState) {
public List<BlockPos> getBlocksToSwap(World world, ItemStack stack, IBlockState swapState, BlockPos pos, IBlockState targetState) {
// If we have no target block passed in, infer it to be
// the block which the swapping is centered on (presumably the block
// which the player is looking at)
if(targetState == null) {
targetState = world.getBlockState(pos);
}
int effrange = RANGE + ItemNBTHelper.getInt(stack, TAG_EXTRA_RANGE, 1);
int diameter = effrange * 2 + 1;
Boolean[][][] matrix = new Boolean[diameter][diameter][diameter];
for(int i = 0; i < diameter; i++)
for(int j = 0; j < diameter; j++)
for(int k = 0; k < diameter; k++) {
BlockPos pos_ = pos.add(i - effrange, j - effrange, k - effrange);
IBlockState state = world.getBlockState(pos_);
boolean invalid = !BlockCamo.isValidBlock(state.getBlock());
if(invalid)
matrix[i][j][k] = true;
else if(state == swapState || state != targetState)
matrix[i][j][k] = null;
else matrix[i][j][k] = false;
}
// Our result list
List<BlockPos> coordsList = new ArrayList<BlockPos>();
return matrix;
}
// We subtract 1 from the effective range as the center tile is included
// So, with a range of 3, we are visiting tiles at -2, -1, 0, 1, 2
int effRange = RANGE + ItemNBTHelper.getInt(stack, TAG_EXTRA_RANGE, 1) - 1;
// Iterate in all 3 dimensions through our possible positions.
for(int offsetX = -effRange; offsetX <= effRange; offsetX++)
for(int offsetY = -effRange; offsetY <= effRange; offsetY++)
for(int offsetZ = -effRange; offsetZ <= effRange; offsetZ++) {
BlockPos pos_ = pos.add(offsetX, offsetY, offsetZ);
public List<BlockPos> getBlocksToSwap(World world, ItemStack stack, IBlockState swapState, BlockPos pos, IBlockState targetState) {
List<BlockPos> coordsList = new ArrayList();
Boolean[][][] matrix = createMatrix(world, stack, swapState, pos, targetState);
int effrange = RANGE + ItemNBTHelper.getInt(stack, TAG_EXTRA_RANGE, 1);
int diameter = effrange * 2;
for(int i = 1; i < diameter; i++)
for(int j = 1; j < diameter; j++)
for(int k = 1; k < diameter; k++) {
BlockPos pos_ = pos.add(i - effrange, j - effrange, k - effrange);
Boolean bool = matrix[i][j][k];
if(bool != null && !bool)
for(EnumFacing dir : EnumFacing.VALUES) {
Boolean obool = matrix[i + dir.getFrontOffsetX()][j + dir.getFrontOffsetY()][k + dir.getFrontOffsetZ()];
if(obool != null && obool) {
coordsList.add(pos_);
break;
}
IBlockState currentState = world.getBlockState(pos_);
// If this block is not our target, ignore it, as we don't need
// to consider replacing it
if(currentState != targetState)
continue;
// If this block is already the block we're swapping to,
// we don't need to swap again
if(currentState == swapState)
continue;
// Check to see if the block is visible on any side:
for(EnumFacing dir : EnumFacing.VALUES) {
BlockPos adjPos = pos_.offset(dir);
Block adjBlock = world.getBlockState(adjPos).getBlock();
// If the side of the adjacent block facing this block is
// _not_ solid, then this block is considered "visible"
// and should be replaced.
// If there is a rendering-specific way to check for this,
// that should be placed in preference to this.
if(!adjBlock.isSideSolid(world, adjPos, dir.getOpposite())) {
coordsList.add(pos_);
break;
}
}
}
return coordsList;
@@ -269,13 +276,23 @@ public class ItemExchangeRod extends ItemMod implements IManaUsingItem, IWirefra
if(player.capabilities.isCreativeMode)
return new ItemStack(block, 1, meta);
return removeFromInventory(player, player.inventory, stack, block, meta, doit);
ItemStack outStack = removeFromInventory(player, BotaniaAPI.internalHandler.getBaublesInventory(player), stack, block, meta, doit);
if (outStack == null)
outStack = removeFromInventory(player, player.inventory, stack, block, meta, doit);
return outStack;
}
public static int getInventoryItemCount(EntityPlayer player, ItemStack stack, Block block, int meta) {
if(player.capabilities.isCreativeMode)
return -1;
return getInventoryItemCount(player, player.inventory, stack, block, meta);
int baubleCount = getInventoryItemCount(player, BotaniaAPI.internalHandler.getBaublesInventory(player), stack, block, meta);
if (baubleCount == -1) return -1;
int count = getInventoryItemCount(player, player.inventory, stack, block, meta);
if (count == -1) return -1;
return count+baubleCount;
}
public static int getInventoryItemCount(EntityPlayer player, IInventory inv, ItemStack stack, Block block, int meta) {