Big code cleanup

This commit is contained in:
mezz committed 2016-05-01 15:34:11 -07:00
1 parent 1b58077904
commit a3363fb4bc
132 files changed
+1587 -1863

No files matched your search

@@ -47,7 +47,7 @@ public enum EnumTreeChromosome implements IChromosomeType {
*/
YIELD(IAlleleFloat.class),
/**
* May add additional tolerances for {@link EnumPlantTypes}.
* May add additional tolerances for {@link EnumPlantType}.
*/
PLANT(IAllelePlantType.class),
/**
@@ -24,7 +24,6 @@ public abstract class ForestryEvent extends Event {
public final GameProfile username;
private BreedingEvent(ISpeciesRoot root, GameProfile username, IBreedingTracker tracker) {
super();
this.root = root;
this.username = username;
this.tracker = tracker;
@@ -54,7 +53,6 @@ public abstract class ForestryEvent extends Event {
public final EntityPlayer player;
public SyncedBreedingTracker(IBreedingTracker tracker, EntityPlayer player) {
super();
this.tracker = tracker;
this.player = player;
}
@@ -5,7 +5,6 @@
******************************************************************************/
package forestry.api.core;
import net.minecraft.item.Item;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -1,11 +1,13 @@
package forestry.api.genetics;
import javax.annotation.Nonnull;
public interface IAlleleProperty<A extends IAlleleProperty<A>> extends IAllele, Comparable<A> {
/**
* To campare the allele for the propertys
* To compare the allele for the properties
*/
@Override
int compareTo(A o);
int compareTo(@Nonnull A o);
}
@@ -13,17 +13,18 @@ package forestry.api.greenhouse;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraftforge.fml.common.eventhandler.Event;
import forestry.api.core.EnumCamouflageType;
import forestry.api.core.ICamouflageHandler;
import forestry.api.core.ICamouflagedBlock;
import net.minecraftforge.fml.common.eventhandler.Event;
public class GreenhouseEvents extends Event {
@Nullable
public final IGreenhouseState state;
public GreenhouseEvents(IGreenhouseState state) {
public GreenhouseEvents(@Nullable IGreenhouseState state) {
this.state = state;
}
@@ -36,7 +37,7 @@ public class GreenhouseEvents extends Event {
@Nonnull
public final EnumCamouflageType camouflageType;
public CamouflageChangeEvent(IGreenhouseState state, ICamouflagedBlock camouflagedBlock, ICamouflageHandler camouflageHandler, EnumCamouflageType camouflageType) {
public CamouflageChangeEvent(IGreenhouseState state, @Nullable ICamouflagedBlock camouflagedBlock, @Nonnull ICamouflageHandler camouflageHandler, @Nonnull EnumCamouflageType camouflageType) {
super(state);
this.camouflagedBlock = camouflagedBlock;
@@ -50,7 +51,7 @@ public class GreenhouseEvents extends Event {
@Nonnull
public IInternalBlock internalBlock;
public InternalBlockEvent(IGreenhouseState state, IInternalBlock internalBlock) {
public InternalBlockEvent(IGreenhouseState state, @Nonnull IInternalBlock internalBlock) {
super(state);
this.internalBlock = internalBlock;
@@ -69,7 +70,7 @@ public class GreenhouseEvents extends Event {
@Nonnull
public final IInternalBlockFace face;
public CheckInternalBlockFaceEvent(IGreenhouseState state, IInternalBlock internalBlock, IInternalBlockFace face) {
public CheckInternalBlockFaceEvent(IGreenhouseState state, IInternalBlock internalBlock, @Nonnull IInternalBlockFace face) {
super(state, internalBlock);
this.face = face;
@@ -14,6 +14,6 @@ public class GreenhouseManager {
public static IGreenhouseHelper greenhouseHelper;
public static List<Class<? extends IGreenhouseLogic>> greenhouseLogics = new ArrayList();
public static List<Class<? extends IGreenhouseLogic>> greenhouseLogics = new ArrayList<>();
}
@@ -14,11 +14,6 @@ import forestry.api.apiculture.DefaultBeeModifier;
import forestry.api.apiculture.IBeeGenome;
public class BeehouseBeeModifier extends DefaultBeeModifier {
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
return 0.25f;
@@ -87,7 +87,6 @@ import forestry.apiculture.genetics.alleles.AlleleEffect;
import forestry.apiculture.items.EnumHoneyComb;
import forestry.apiculture.items.EnumPollenCluster;
import forestry.apiculture.items.EnumPropolis;
import forestry.apiculture.items.ItemHabitatLocator;
import forestry.apiculture.items.ItemRegistryApiculture;
import forestry.apiculture.multiblock.TileAlvearyFan;
import forestry.apiculture.multiblock.TileAlvearyHeater;
@@ -258,7 +257,7 @@ public class PluginApiculture extends BlankForestryPlugin {
parsePlantableFlowers(property, flowerType);
Set<Flower> acceptableFlowers = flowerRegistry.getAcceptableFlowers(flowerType);
if (acceptableFlowers == null || acceptableFlowers.size() == 0) {
if (acceptableFlowers == null || acceptableFlowers.isEmpty()) {
Log.error("Flower type '" + flowerType + "' has no valid flowers set in apiculture.cfg. Add valid flowers or delete the config to set it to default.");
}
}
@@ -691,7 +690,7 @@ public class PluginApiculture extends BlankForestryPlugin {
));
// Irradiated combs
RecipeManagers.centrifugeManager.addRecipe(20, items.beeComb.get(EnumHoneyComb.IRRADIATED, 1), ImmutableMap.<ItemStack, Float>of(
RecipeManagers.centrifugeManager.addRecipe(20, items.beeComb.get(EnumHoneyComb.IRRADIATED, 1), ImmutableMap.of(
));
// Powdery combs
@@ -37,7 +37,6 @@ import forestry.core.utils.BlockUtil;
public class BlockStump extends BlockTorch implements IItemModelRegister {
public BlockStump() {
super();
this.setHardness(0.0F);
this.setStepSound(soundTypeWood);
setCreativeTab(Tabs.tabApiculture);
@@ -93,9 +93,4 @@ public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase {
public Object getContainer(EntityPlayer player, int data) {
return new ContainerMinecartBeehouse(player.inventory, this, false);
}
@Override
public int getIdOfEntity() {
return getEntityId();
}
}
@@ -65,7 +65,7 @@ public class ApiaristTracker extends BreedingTracker implements IApiaristTracker
return;
}
if (speciesRoot.getCombinations(individual.getGenome().getPrimary()).size() > 0) {
if (!speciesRoot.getCombinations(individual.getGenome().getPrimary()).isEmpty()) {
return;
}
@@ -573,7 +573,7 @@ public class Bee extends IndividualLiving implements IBee {
}
}
if (bees.size() > 0) {
if (!bees.isEmpty()) {
return bees.toArray(new IBee[bees.size()]);
} else {
return null;
@@ -79,7 +79,7 @@ public class AlleleEffectResurrection extends AlleleEffectThrottled {
@Override
public IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
List<EntityItem> entities = getEntitiesInRange(genome, housing, EntityItem.class);
if (entities.size() == 0) {
if (entities.isEmpty()) {
return storedData;
}
@@ -60,6 +60,7 @@ public class ItemHabitatLocator extends ItemWithGui implements ISpriteRegister {
}
/* SPRITES */
@Override
@SideOnly(Side.CLIENT)
public void registerSprites(ITextureManager manager) {
TextureAtlasSprite texture = new TextureHabitatLocator(iconName);
@@ -28,7 +28,6 @@ import forestry.core.items.ItemForestry;
public class ItemHoneyComb extends ItemForestry {
public ItemHoneyComb() {
super();
setMaxDamage(0);
setHasSubtypes(true);
setCreativeTab(Tabs.tabApiculture);
@@ -62,7 +62,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory,
/* UPDATING */
@Override
public void updateServer(int tickCount) {
if (pendingSpawns.size() > 0) {
if (!pendingSpawns.isEmpty()) {
setActive(true);
if (tickCount % 1000 == 0) {
trySpawnSwarm();
@@ -12,6 +12,7 @@ package forestry.apiculture.network.packets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.apiculture.multiblock.IAlvearyControllerInternal;
import forestry.core.network.DataInputStreamForestry;
@@ -38,7 +39,7 @@ public class PacketAlveryChange extends PacketCoordinates implements IForestryPa
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) {
TileEntity tile = getTarget(Proxies.common.getRenderWorld());
if (tile instanceof IMultiblockComponent) {
((IMultiblockComponent) tile).getMultiblockLogic().getController().reassemble();;
((IMultiblockComponent) tile).getMultiblockLogic().getController().reassemble();
}
}
}
@@ -164,11 +164,6 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
return getAccessHandler().getOwner();
}
@Override
public World getWorld() {
return worldObj;
}
@Override
public Vec3 getBeeFXCoordinates() {
return new Vec3(getPos().getX() + 0.5, getPos().getY() + 0.5, getPos().getZ() + 0.5);
@@ -40,7 +40,7 @@ public class TriggerNoFrames extends Trigger {
InventoryApiary inventory = (InventoryApiary) apiary.getInternalInventory();
return inventory.getFrames().size() == 0;
return inventory.getFrames().isEmpty();
}
}
@@ -150,7 +150,7 @@ public class AlleleFruit extends AlleleCategorized implements IAlleleFruit {
}
@Override
public int compareTo(IAlleleFruit o) {
public int compareTo(@Nonnull IAlleleFruit o) {
return 0;
}
@@ -163,7 +163,7 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
}
@Override
public int compareTo(IAlleleTreeSpecies o) {
public int compareTo(@Nonnull IAlleleTreeSpecies o) {
return 0;
}
@@ -234,7 +234,7 @@ public class GuiTreealyzer extends GuiAlyzer {
strike = "";
IAlleleFruit fruit1 = (IAlleleFruit) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS);
if (!tree.getGenome().getSecondary().getSuitableFruit().contains(((IAlleleFruit) fruit1).getProvider().getFamily()) && fruit1 != AlleleFruit.fruitNone) {
if (!tree.getGenome().getSecondary().getSuitableFruit().contains(fruit1.getProvider().getFamily()) && fruit1 != AlleleFruit.fruitNone) {
strike = EnumChatFormatting.STRIKETHROUGH.toString();
}
textLayout.drawLine(strike + fruit1.getProvider().getDescription(), COLUMN_2, fruitDominance1);
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.arboriculture.models;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -17,7 +19,9 @@ import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.IExtendedBlockState;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.ILeafSpriteProvider;
import forestry.api.arboriculture.ITreeGenome;
@@ -70,12 +74,12 @@ public class ModelDecorativeLeaves extends ModelBlockOverlay<BlockDecorativeLeav
}
@Override
protected void bakeInventoryBlock(BlockDecorativeLeaves block, ItemStack item, IModelBaker baker) {
protected void bakeInventoryBlock(@Nonnull BlockDecorativeLeaves block, @Nonnull ItemStack item, @Nonnull IModelBaker baker) {
}
@Override
protected void bakeWorldBlock(BlockDecorativeLeaves block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) {
protected void bakeWorldBlock(@Nonnull BlockDecorativeLeaves block, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IExtendedBlockState stateExtended, @Nonnull IModelBaker baker) {
}
public static void bakeBlock(BlockDecorativeLeaves block, TreeDefinition treeDefinition, IModelBaker baker) {
@@ -10,11 +10,15 @@
******************************************************************************/
package forestry.arboriculture.models;
import javax.annotation.Nonnull;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.IExtendedBlockState;
import forestry.api.core.IModelBaker;
import forestry.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.genetics.TreeRoot;
@@ -31,7 +35,7 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
}
@Override
public void bakeInventoryBlock(BlockForestryLeaves block, ItemStack itemStack, IModelBaker baker) {
public void bakeInventoryBlock(@Nonnull BlockForestryLeaves block, @Nonnull ItemStack itemStack, @Nonnull IModelBaker baker) {
if (!(itemStack.getItem() instanceof ItemBlockLeaves) || block == null) {
return;
}
@@ -63,7 +67,7 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
}
@Override
public void bakeWorldBlock(BlockForestryLeaves block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) {
public void bakeWorldBlock(@Nonnull BlockForestryLeaves block, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IExtendedBlockState stateExtended, @Nonnull IModelBaker baker) {
TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class);
if (tile == null) {
return;
@@ -117,13 +117,14 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
}
/* IOwnable */
@Nullable
@Override
public GameProfile getOwner() {
return owner;
}
@Override
public void setOwner(GameProfile owner) {
public void setOwner(@Nullable GameProfile owner) {
this.owner = owner;
}
@@ -59,7 +59,7 @@ public class TickHandlerCoreServer {
int dimensionID = world.provider.getDimensionId();
List<ChunkCoords> chunkList = chunkRegenList.get(dimensionID);
if (chunkList.size() > 0) {
if (!chunkList.isEmpty()) {
ChunkCoords coords = chunkList.get(0);
chunkList.remove(0);
@@ -20,7 +20,6 @@ import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
@@ -55,7 +54,6 @@ import forestry.core.proxy.Proxies;
import forestry.core.render.MachineParticleCallback;
import forestry.core.render.MachineStateMapper;
import forestry.core.render.ParticleHelper;
import forestry.core.render.TextureManager;
import forestry.core.tiles.TileBase;
import forestry.core.tiles.TileForestry;
import forestry.core.tiles.TileUtil;
@@ -97,7 +95,7 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
IBlockState state = this.blockState.getBaseState().withProperty(FACE, EnumFacing.NORTH);
this.setDefaultState(state);
particleCallback = new MachineParticleCallback(this, TYPE);
particleCallback = new MachineParticleCallback<>(this, TYPE);
}
public PropertyEnum<P> getTypeProperty() {
@@ -10,11 +10,6 @@
******************************************************************************/
package forestry.core.blocks;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class BlockCore extends BlockBase<BlockTypeCoreTesr> {
public BlockCore() {
super(BlockTypeCoreTesr.class);
@@ -10,7 +10,6 @@
******************************************************************************/
package forestry.core.blocks;
import forestry.core.utils.Translator;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
@@ -31,6 +30,7 @@ import forestry.core.circuits.ISocketable;
import forestry.core.multiblock.MultiblockTileEntityForestry;
import forestry.core.multiblock.MultiblockUtil;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.Translator;
public abstract class BlockStructure extends BlockForestry {
@@ -120,7 +120,7 @@ public abstract class BlockStructure extends BlockForestry {
IMultiblockComponent part = (IMultiblockComponent) tile;
// drop inventory if we're the last part remaining
if (MultiblockUtil.getNeighboringParts(world, part).size() == 0) {
if (MultiblockUtil.getNeighboringParts(world, part).isEmpty()) {
if (tile instanceof IInventory) {
InventoryUtil.dropInventory((IInventory) tile, world, pos);
}
@@ -20,13 +20,13 @@ public class MachinePropertiesTesr<T extends TileForestry> extends MachineProper
@Nonnull
private final String particleTextureLocation;
public MachinePropertiesTesr(int meta, @Nonnull Class<T> teClass, @Nonnull String name, @Nullable TileEntitySpecialRenderer<? super T> renderer, String particleTextureLocation) {
public MachinePropertiesTesr(int meta, @Nonnull Class<T> teClass, @Nonnull String name, @Nullable TileEntitySpecialRenderer<? super T> renderer, @Nonnull String particleTextureLocation) {
super(meta, teClass, name);
this.renderer = renderer;
this.particleTextureLocation = particleTextureLocation;
}
public MachinePropertiesTesr(int meta, @Nonnull Class<T> teClass, @Nonnull String name, @Nullable TileEntitySpecialRenderer<? super T> renderer, @Nonnull AxisAlignedBB boundingBox, String particleTextureLocation) {
public MachinePropertiesTesr(int meta, @Nonnull Class<T> teClass, @Nonnull String name, @Nullable TileEntitySpecialRenderer<? super T> renderer, @Nonnull AxisAlignedBB boundingBox, @Nonnull String particleTextureLocation) {
super(meta, teClass, name, boundingBox);
this.renderer = renderer;
this.particleTextureLocation = particleTextureLocation;
@@ -33,7 +33,6 @@ import forestry.core.items.ItemForestry;
public class ItemCircuitBoard extends ItemForestry {
public ItemCircuitBoard() {
super();
setHasSubtypes(true);
}
@@ -109,7 +109,7 @@ public class CommandHelpers {
body.setColor(EnumChatFormatting.GRAY);
List<String> commandAliases = command.getCommandAliases();
if (commandAliases.size() > 0) {
if (!commandAliases.isEmpty()) {
sendLocalizedChatMessage(sender, body, "for.chat.command.aliases", commandAliases.toString().replace("[", "").replace("]", ""));
}
@@ -25,6 +25,7 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;
import forestry.core.PluginFluids;
import forestry.core.config.Constants;
import forestry.core.utils.InventoryUtil;
@@ -173,7 +173,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
final int count = nbttagcompound.getInteger(countKey);
for (int i = 0; i < count; i++) {
String value = nbttagcompound.getString(key + i);
if (value != null && value.length() > 0) {
if (value != null && !value.isEmpty()) {
values.add(value);
}
}
@@ -186,7 +186,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
Iterator<String> iterator = values.iterator();
for (int i = 0; i < count; i++) {
String value = iterator.next();
if (value != null && value.length() > 0) {
if (value != null && !value.isEmpty()) {
nbttagcompound.setString(key + i, value);
}
}
@@ -256,7 +256,6 @@ public class ItemResearchNote extends ItemForestry {
}
public ItemResearchNote() {
super();
setCreativeTab(null);
}
@@ -107,7 +107,7 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuil
ItemStack research = null;
if (world.rand.nextFloat() < (float) 10 / bountyLevel) {
Collection<? extends IMutation> combinations = getRoot().getCombinations(this);
if (combinations.size() > 0) {
if (!combinations.isEmpty()) {
IMutation[] candidates = combinations.toArray(new IMutation[combinations.size()]);
research = AlleleManager.alleleRegistry.getMutationNoteStack(researcher, candidates[world.rand.nextInt(candidates.length)]);
}
@@ -35,7 +35,7 @@ public class MutationConditionRequiresResourceOreDict implements IMutationCondit
this.oreDictId = OreDictionary.getOreID(oreDictName);
List<ItemStack> ores = OreDictionary.getOres(oreDictName);
if (ores != null && 0 < ores.size()) {
if (ores != null && !ores.isEmpty()) {
this.displayName = ores.get(0).getDisplayName();
} else {
this.displayName = oreDictName;
@@ -112,7 +112,7 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
if (Config.enableHints && inventory instanceof IHintSource) {
IHintSource hintSource = (IHintSource) inventory;
List<String> hints = hintSource.getHints();
if (hints != null && hints.size() > 0) {
if (hints != null && !hints.isEmpty()) {
ledgerManager.add(new HintLedger(ledgerManager, hintSource));
}
}
@@ -62,7 +62,7 @@ public class GuiIdRegistry {
private static int nextId = 0;
static {
registerGuiHandlers(GuiType.Tile, Arrays.<Class<? extends IGuiHandlerForestry>>asList(
registerGuiHandlers(GuiType.Tile, Arrays.asList(
TileAlveary.class,
TileAlvearyHygroregulator.class,
TileAlvearySieve.class,
@@ -98,7 +98,7 @@ public class GuiIdRegistry {
TileTrader.class
));
registerGuiHandlers(GuiType.Item, Arrays.<Class<? extends IGuiHandlerForestry>>asList(
registerGuiHandlers(GuiType.Item, Arrays.asList(
ItemBackpack.class,
ItemBackpackNaturalist.class,
ItemBeealyzer.class,
@@ -112,7 +112,7 @@ public class GuiIdRegistry {
ItemTreealyzer.class
));
registerGuiHandlers(GuiType.Entity, Arrays.<Class<? extends IGuiHandlerForestry>>asList(
registerGuiHandlers(GuiType.Entity, Arrays.asList(
EntityMinecartApiary.class,
EntityMinecartBeehouse.class
));
@@ -11,6 +11,7 @@
package forestry.core.inventory;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.items.IItemHandler;
/**
@@ -19,17 +20,17 @@ import net.minecraftforge.items.IItemHandler;
* @author CovertJaguar <http://www.railcraft.info>
*/
public class InventoryObject {
private Object inventory;
private final Object inventory;
public InventoryObject(IInventory inventory) {
this.inventory = inventory;
}
public InventoryObject(IInventory inventory) {
this.inventory = inventory;
}
public InventoryObject(IItemHandler inventory) {
this.inventory = inventory;
}
public InventoryObject(IItemHandler inventory) {
this.inventory = inventory;
}
public Object getObject() {
return inventory;
}
public Object getObject() {
return inventory;
}
}
@@ -1,29 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.inventory;
import net.minecraftforge.items.wrapper.InvWrapper;
public class ItemHandlerItemInventory<I extends ItemInventory> extends InvWrapper {
private I itemInventory;
public ItemHandlerItemInventory(I inv) {
super(inv);
itemInventory = inv;
}
public I getItemInventory() {
return itemInventory;
}
}
@@ -24,6 +24,7 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import forestry.core.tiles.IFilterSlotDelegate;
@@ -32,7 +33,7 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate,
private static final String KEY_UID = "UID";
private static final Random rand = new Random();
private final IItemHandler capabilityHandler = new ItemHandlerItemInventory<>(this);
private final IItemHandler capabilityHandler = new InvWrapper(this);
private final EntityPlayer player;
private final ItemStack parent;
private final ItemStack[] inventoryStacks;
@@ -19,30 +19,30 @@ import forestry.core.utils.InventoryUtil;
*/
public class ArrayStackFilter extends StackFilter {
private final ItemStack[] stacks;
private final ItemStack[] stacks;
public ArrayStackFilter(ItemStack... stacks) {
this.stacks = stacks;
}
public ArrayStackFilter(ItemStack... stacks) {
this.stacks = stacks;
}
@Override
public boolean apply(final ItemStack stack) {
if (stacks.length == 0 || !hasFilter()) {
return true;
}
return InventoryUtil.isItemEqual(stack, stacks);
}
@Override
public boolean apply(final ItemStack stack) {
if (stacks.length == 0 || !hasFilter()) {
return true;
}
return InventoryUtil.isItemEqual(stack, stacks);
}
public ItemStack[] getStacks() {
return stacks;
}
public ItemStack[] getStacks() {
return stacks;
}
public boolean hasFilter() {
for (ItemStack filter : stacks) {
if (filter != null) {
return true;
}
}
return false;
}
public boolean hasFilter() {
for (ItemStack filter : stacks) {
if (filter != null) {
return true;
}
}
return false;
}
}
@@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.inventory.filters;
import forestry.core.utils.InventoryUtil;
import net.minecraft.item.ItemStack;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public class ExclusionStackFilter extends StackFilter {
private final ItemStack[] exclude;
public ExclusionStackFilter(ItemStack... exclude) {
this.exclude = exclude;
}
@Override
public boolean apply(final ItemStack stack) {
if (stack == null) {
return false;
}
return !InventoryUtil.isItemEqual(stack, exclude);
}
}
@@ -11,10 +11,11 @@
package forestry.core.inventory.filters;
import com.google.common.base.Predicate;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
/**
* This interface is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
*
@@ -22,9 +23,9 @@ import javax.annotation.Nonnull;
*/
public interface IStackFilter extends Predicate<ItemStack> {
StackFilter and(@Nonnull Predicate<? super ItemStack>... other);
StackFilter and(@Nonnull Predicate<? super ItemStack>... other);
StackFilter or(@Nonnull Predicate<? super ItemStack>... other);
StackFilter or(@Nonnull Predicate<? super ItemStack>... other);
StackFilter negate();
StackFilter negate();
}
@@ -1,32 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.inventory.filters;
import forestry.core.utils.InventoryUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public class InventoryStackFilter extends StackFilter {
private final IInventory inv;
public InventoryStackFilter(IInventory inv) {
this.inv = inv;
}
@Override
public boolean apply(final ItemStack stack) {
return InventoryUtil.containsItem(inv, stack);
}
}
@@ -11,7 +11,6 @@
package forestry.core.inventory.filters;
import com.google.common.base.Predicate;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -19,6 +18,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import net.minecraft.item.ItemStack;
/**
* This class is used to provide a convenient means of dealing with entire classes of items without having to specify each item individually.
*
@@ -26,97 +27,97 @@ import java.util.Objects;
*/
@SuppressWarnings("unused")
public class StackFilter implements IStackFilter {
/**
* Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
* <p/>
* Feel free to grab them from here or define your own.
*/
public static final Map<String, IStackFilter> standardFilters = new HashMap<String, IStackFilter>();
/**
* Railcraft adds the following IItemTypes during preInit: ALL, FUEL, TRACK, MINECART, BALLAST, FEED
* <p/>
* Feel free to grab them from here or define your own.
*/
public static final Map<String, IStackFilter> standardFilters = new HashMap<>();
@Override
public boolean apply(@Nullable final ItemStack input) {
return true;
}
@Override
public boolean apply(@Nullable final ItemStack input) {
return true;
}
@Override
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (!filter.apply(stack)) {
@Override
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (!filter.apply(stack)) {
return false;
}
}
return StackFilter.this.apply(stack);
}
};
}
}
return StackFilter.this.apply(stack);
}
};
}
@Override
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (filter.apply(stack)) {
@Override
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (filter.apply(stack)) {
return true;
}
}
return StackFilter.this.apply(stack);
}
};
}
}
return StackFilter.this.apply(stack);
}
};
}
@Override
public final StackFilter negate() {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !StackFilter.this.apply(stack);
}
};
}
@Override
public final StackFilter negate() {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !StackFilter.this.apply(stack);
}
};
}
public static StackFilter buildAnd(@Nonnull final Predicate<? super ItemStack>... filters) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
Objects.requireNonNull(stack);
for (Predicate<? super ItemStack> filter : filters) {
if (!filter.apply(stack)) {
public static StackFilter buildAnd(@Nonnull final Predicate<? super ItemStack>... filters) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
Objects.requireNonNull(stack);
for (Predicate<? super ItemStack> filter : filters) {
if (!filter.apply(stack)) {
return false;
}
}
return true;
}
};
}
}
return true;
}
};
}
public static StackFilter buildOr(@Nonnull final Predicate<? super ItemStack>... filters) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
Objects.requireNonNull(stack);
for (Predicate<? super ItemStack> filter : filters) {
if (filter.apply(stack)) {
public static StackFilter buildOr(@Nonnull final Predicate<? super ItemStack>... filters) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
Objects.requireNonNull(stack);
for (Predicate<? super ItemStack> filter : filters) {
if (filter.apply(stack)) {
return true;
}
}
return false;
}
};
}
}
return false;
}
};
}
public static StackFilter invert(@Nonnull final Predicate<? super ItemStack> filter) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !filter.apply(stack);
}
};
}
public static StackFilter invert(@Nonnull final Predicate<? super ItemStack> filter) {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !filter.apply(stack);
}
};
}
}
@@ -11,13 +11,16 @@
package forestry.core.inventory.filters;
import com.google.common.base.Predicate;
import net.minecraft.init.Items;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntityFurnace;
import javax.annotation.Nonnull;
import java.util.Objects;
import net.minecraft.init.Items;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
/**
* This interface is used with several of the functions in IItemTransfer to
* provide a convenient means of dealing with entire classes of items without
@@ -46,55 +49,55 @@ public enum StandardStackFilters implements IStackFilter {
}
};
public static void initialize() {
for (StandardStackFilters type : StandardStackFilters.values()) {
StackFilter.standardFilters.put(type.name(), type);
}
}
public static void initialize() {
for (StandardStackFilters type : StandardStackFilters.values()) {
StackFilter.standardFilters.put(type.name(), type);
}
}
@Override
public abstract boolean apply(ItemStack stack);
@Override
public abstract boolean apply(ItemStack stack);
@Override
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (!filter.apply(stack)) {
@Override
public final StackFilter and(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (!filter.apply(stack)) {
return false;
}
}
return StandardStackFilters.this.apply(stack);
}
};
}
}
return StandardStackFilters.this.apply(stack);
}
};
}
@Override
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (filter.apply(stack)) {
@Override
public final StackFilter or(@Nonnull final Predicate<? super ItemStack>... other) {
Objects.requireNonNull(other);
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
for (Predicate<? super ItemStack> filter : other) {
if (filter.apply(stack)) {
return true;
}
}
return StandardStackFilters.this.apply(stack);
}
};
}
}
return StandardStackFilters.this.apply(stack);
}
};
}
@Override
public final StackFilter negate() {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !StandardStackFilters.this.apply(stack);
}
};
}
@Override
public final StackFilter negate() {
return new StackFilter() {
@Override
public boolean apply(ItemStack stack) {
return !StandardStackFilters.this.apply(stack);
}
};
}
}
@@ -23,8 +23,8 @@ import net.minecraft.item.ItemStack;
* @author CovertJaguar <http://www.railcraft.info>
*/
public interface IExtInvSlot extends IInvSlot {
/**
* Sets the current ItemStack in the slot.
*/
void setStackInSlot(ItemStack stack);
/**
* Sets the current ItemStack in the slot.
*/
void setStackInSlot(ItemStack stack);
}
@@ -19,19 +19,19 @@ import net.minecraft.item.ItemStack;
*/
public interface IInvSlot {
boolean canPutStackInSlot(ItemStack stack);
boolean canPutStackInSlot(ItemStack stack);
boolean canTakeStackFromSlot(ItemStack stack);
boolean canTakeStackFromSlot(ItemStack stack);
ItemStack decreaseStackInSlot();
ItemStack decreaseStackInSlot();
/**
* It is not legal to edit the stack returned from this function.
*/
ItemStack getStackInSlot();
/**
* It is not legal to edit the stack returned from this function.
*/
ItemStack getStackInSlot();
// void setStackInSlot(ItemStack stack);
int getIndex();
int getIndex();
}
@@ -12,49 +12,22 @@ package forestry.core.inventory.iterators;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
import java.util.List;
import forestry.core.inventory.InventoryObject;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public abstract class InventoryIterator<T extends IInvSlot> implements Iterable<T> {
public static InventoryIterator<IExtInvSlot> getIterable(IInventory inv) {
if (inv instanceof ISidedInventory) {
public static InventoryIterator<IExtInvSlot> getIterable(IInventory inv) {
if (inv instanceof ISidedInventory) {
return new SidedInventoryIterator((ISidedInventory) inv);
}
return new StandardInventoryIterator(inv);
}
return new StandardInventoryIterator(inv);
}
public static InventoryIterator<IInvSlot> getIterable(IItemHandler inv) {
return new ItemHandlerInventoryIterator(inv);
}
public static InventoryIterator<? extends IInvSlot> getIterable(InventoryObject inv) {
if (inv.getObject() instanceof ISidedInventory) {
return new SidedInventoryIterator((ISidedInventory) inv.getObject());
}
if (inv.getObject() instanceof IInventory) {
return new StandardInventoryIterator((IInventory) inv.getObject());
}
if (inv.getObject() instanceof IItemHandler) {
return new ItemHandlerInventoryIterator((IItemHandler) inv.getObject());
}
throw new RuntimeException("Invalid Inventory Object");
}
public Iterable<T> notNull() {
List<T> filledSlots = new ArrayList<T>(32);
for (T slot : this) {
if (slot.getStackInSlot() != null) {
filledSlots.add(slot);
}
}
return filledSlots;
}
public static InventoryIterator<IInvSlot> getIterable(IItemHandler inv) {
return new ItemHandlerInventoryIterator(inv);
}
}
@@ -10,11 +10,12 @@
******************************************************************************/
package forestry.core.inventory.iterators;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.Iterator;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import forestry.core.utils.InventoryUtil;
/**
@@ -22,67 +23,67 @@ import forestry.core.utils.InventoryUtil;
*/
public class ItemHandlerInventoryIterator extends InventoryIterator<IInvSlot> {
private final IItemHandler inv;
private final IItemHandler inv;
protected ItemHandlerInventoryIterator(IItemHandler inv) {
this.inv = inv;
}
protected ItemHandlerInventoryIterator(IItemHandler inv) {
this.inv = inv;
}
@Override
public Iterator<IInvSlot> iterator() {
return new Iterator<IInvSlot>() {
int slot = 0;
@Override
public Iterator<IInvSlot> iterator() {
return new Iterator<IInvSlot>() {
int slot = 0;
@Override
public boolean hasNext() {
return slot < inv.getSlots();
}
@Override
public boolean hasNext() {
return slot < inv.getSlots();
}
@Override
public IInvSlot next() {
return new InvSlot(slot++);
}
@Override
public IInvSlot next() {
return new InvSlot(slot++);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
};
}
};
}
private class InvSlot implements IInvSlot {
private class InvSlot implements IInvSlot {
protected final int slot;
protected final int slot;
public InvSlot(int slot) {
this.slot = slot;
}
public InvSlot(int slot) {
this.slot = slot;
}
@Override
public int getIndex() {
return slot;
}
@Override
public int getIndex() {
return slot;
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.insertItem(slot, stack, true) == null;
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.insertItem(slot, stack, true) == null;
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return inv.extractItem(slot, 1, true) != null;
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return inv.extractItem(slot, 1, true) != null;
}
@Override
public ItemStack decreaseStackInSlot() {
return inv.extractItem(slot, 1, false);
}
@Override
public ItemStack decreaseStackInSlot() {
return inv.extractItem(slot, 1, false);
}
@Override
public ItemStack getStackInSlot() {
return InventoryUtil.makeSafe(inv.getStackInSlot(slot));
}
@Override
public ItemStack getStackInSlot() {
return InventoryUtil.makeSafe(inv.getStackInSlot(slot));
}
}
}
}
@@ -10,63 +10,63 @@
******************************************************************************/
package forestry.core.inventory.iterators;
import java.util.Iterator;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import java.util.Iterator;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public class SidedInventoryIterator extends StandardInventoryIterator {
private final ISidedInventory inv;
private final ISidedInventory inv;
protected SidedInventoryIterator(ISidedInventory inv) {
super(inv);
this.inv = inv;
}
protected SidedInventoryIterator(ISidedInventory inv) {
super(inv);
this.inv = inv;
}
@Override
public Iterator<IExtInvSlot> iterator() {
return new Iterator<IExtInvSlot>() {
int[] slots = inv.getSlotsForFace(EnumFacing.DOWN);
int index = 0;
@Override
public Iterator<IExtInvSlot> iterator() {
return new Iterator<IExtInvSlot>() {
int[] slots = inv.getSlotsForFace(EnumFacing.DOWN);
int index = 0;
@Override
public boolean hasNext() {
return slots != null && index < slots.length;
}
@Override
public boolean hasNext() {
return slots != null && index < slots.length;
}
@Override
public IExtInvSlot next() {
return new InvSlot(slots[index++]);
}
@Override
public IExtInvSlot next() {
return new InvSlot(slots[index++]);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
};
}
};
}
private class InvSlot extends StandardInventoryIterator.InvSlot implements IExtInvSlot {
private class InvSlot extends StandardInventoryIterator.InvSlot implements IExtInvSlot {
public InvSlot(int slot) {
super(slot);
}
public InvSlot(int slot) {
super(slot);
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.canInsertItem(slot, stack, EnumFacing.DOWN);
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.canInsertItem(slot, stack, EnumFacing.DOWN);
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return inv.canExtractItem(slot, stack, EnumFacing.DOWN);
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return inv.canExtractItem(slot, stack, EnumFacing.DOWN);
}
}
}
}
@@ -11,90 +11,90 @@
package forestry.core.inventory.iterators;
import java.util.Iterator;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import java.util.Iterator;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public class StandardInventoryIterator extends InventoryIterator<IExtInvSlot> {
private final IInventory inv;
private final int invSize;
private final IInventory inv;
private final int invSize;
protected StandardInventoryIterator(IInventory inv) {
this.inv = inv;
this.invSize = inv.getSizeInventory();
}
protected StandardInventoryIterator(IInventory inv) {
this.inv = inv;
this.invSize = inv.getSizeInventory();
}
@Override
public Iterator<IExtInvSlot> iterator() {
return new Iterator<IExtInvSlot>() {
int slot = 0;
@Override
public Iterator<IExtInvSlot> iterator() {
return new Iterator<IExtInvSlot>() {
int slot = 0;
@Override
public boolean hasNext() {
return slot < invSize;
}
@Override
public boolean hasNext() {
return slot < invSize;
}
@Override
public IExtInvSlot next() {
return new InvSlot(slot++);
}
@Override
public IExtInvSlot next() {
return new InvSlot(slot++);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
};
}
};
}
class InvSlot implements IExtInvSlot {
class InvSlot implements IExtInvSlot {
protected final int slot;
protected final int slot;
public InvSlot(int slot) {
this.slot = slot;
}
public InvSlot(int slot) {
this.slot = slot;
}
@Override
public ItemStack getStackInSlot() {
return inv.getStackInSlot(slot);
}
@Override
public ItemStack getStackInSlot() {
return inv.getStackInSlot(slot);
}
@Override
public void setStackInSlot(ItemStack stack) {
inv.setInventorySlotContents(slot, stack);
}
@Override
public void setStackInSlot(ItemStack stack) {
inv.setInventorySlotContents(slot, stack);
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.isItemValidForSlot(slot, stack);
}
@Override
public boolean canPutStackInSlot(ItemStack stack) {
return inv.isItemValidForSlot(slot, stack);
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return true;
}
@Override
public boolean canTakeStackFromSlot(ItemStack stack) {
return true;
}
@Override
public ItemStack decreaseStackInSlot() {
return inv.decrStackSize(slot, 1);
}
@Override
public ItemStack decreaseStackInSlot() {
return inv.decrStackSize(slot, 1);
}
@Override
public int getIndex() {
return slot;
}
@Override
public int getIndex() {
return slot;
}
@Override
public String toString() {
ItemStack stack = getStackInSlot();
return "SlotNum = " + slot + " Stack = " + (stack == null ? "null" : getStackInSlot().toString());
}
@Override
public String toString() {
ItemStack stack = getStackInSlot();
return "SlotNum = " + slot + " Stack = " + (stack == null ? "null" : getStackInSlot().toString());
}
}
}
}
@@ -12,9 +12,8 @@ package forestry.core.inventory.manipulators;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import net.minecraftforge.items.IItemHandler;
import forestry.core.inventory.InventoryObject;
import forestry.core.inventory.filters.IStackFilter;
@@ -26,116 +25,53 @@ import forestry.core.inventory.iterators.IInvSlot;
*/
public abstract class InventoryManipulator<T extends IInvSlot> implements Iterable<T> {
public static InventoryManipulator<IExtInvSlot> get(IInventory inv) {
return new StandardInventoryManipulator(inv);
}
public static InventoryManipulator<IExtInvSlot> get(IInventory inv) {
return new StandardInventoryManipulator(inv);
}
public static InventoryManipulator<IInvSlot> get(IItemHandler inv) {
return new ItemHandlerInventoryManipulator(inv);
}
public static InventoryManipulator<IInvSlot> get(IItemHandler inv) {
return new ItemHandlerInventoryManipulator(inv);
}
public static InventoryManipulator<? extends IInvSlot> get(InventoryObject inv) {
if (inv.getObject() instanceof IInventory) {
public static InventoryManipulator<? extends IInvSlot> get(InventoryObject inv) {
if (inv.getObject() instanceof IInventory) {
return new StandardInventoryManipulator((IInventory) inv.getObject());
}
if (inv.getObject() instanceof IItemHandler) {
if (inv.getObject() instanceof IItemHandler) {
return new ItemHandlerInventoryManipulator((IItemHandler) inv.getObject());
}
throw new RuntimeException("Invalid Inventory Object");
}
throw new RuntimeException("Invalid Inventory Object");
}
protected InventoryManipulator() {
}
protected InventoryManipulator() {
}
public boolean canAddStack(ItemStack stack) {
return tryAddStack(stack) == null;
}
public ItemStack tryAddStack(ItemStack stack) {
return addStack(stack, false);
}
public ItemStack tryAddStack(ItemStack stack) {
return addStack(stack, false);
}
/**
* Attempt to add the stack to the inventory.
*
* @return The remainder
*/
public ItemStack addStack(ItemStack stack) {
return addStack(stack, true);
}
/**
* Attempt to add the stack to the inventory.
*
* @return The remainder
*/
public ItemStack addStack(ItemStack stack) {
return addStack(stack, true);
}
protected abstract ItemStack addStack(ItemStack stack, boolean doAdd);
protected abstract ItemStack addStack(ItemStack stack, boolean doAdd);
/**
* Returns true if an item matching the filter can be removed from the
* inventory.
*/
public boolean canRemoveItem(IStackFilter filter) {
return tryRemoveItem(filter) == null;
}
/**
* Returns the item that would be returned if an item matching the filter
* was removed. Does not modify the inventory.
*/
public ItemStack tryRemoveItem(IStackFilter filter) {
for (IInvSlot slot : this) {
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
ItemStack output = stack.copy();
output.stackSize = 1;
return output;
}
}
return null;
}
/**
* Removed an item matching the filter.
*/
public ItemStack removeItem(IStackFilter filter) {
for (IInvSlot slot : this) {
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
/**
* Removed an item matching the filter.
*/
public ItemStack removeItem(IStackFilter filter) {
for (IInvSlot slot : this) {
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
return slot.decreaseStackInSlot();
}
}
return null;
}
public boolean canRemoveItems(IStackFilter filter, int maxAmount) {
List<ItemStack> outputList = removeItem(filter, maxAmount, false);
int found = 0;
for (ItemStack stack : outputList) {
found += stack.stackSize;
}
return found == maxAmount;
}
public List<ItemStack> removeItems(IStackFilter filter, int maxAmount) {
return removeItem(filter, maxAmount, true);
}
protected abstract List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove);
public ItemStack moveItem(IInventory dest, IStackFilter filter) {
return moveItem(new InventoryObject(dest), filter);
}
public ItemStack moveItem(InventoryObject dest, IStackFilter filter) {
InventoryManipulator imDest = InventoryManipulator.get(dest);
for (IInvSlot slot : this) {
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
stack = stack.copy();
stack.stackSize = 1;
stack = imDest.addStack(stack);
if (stack == null) {
return slot.decreaseStackInSlot();
}
}
}
return null;
}
}
return null;
}
}
@@ -10,13 +10,14 @@
******************************************************************************/
package forestry.core.inventory.manipulators;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import forestry.core.inventory.filters.IStackFilter;
import forestry.core.inventory.iterators.IInvSlot;
import forestry.core.inventory.iterators.InventoryIterator;
@@ -26,81 +27,61 @@ import forestry.core.inventory.iterators.InventoryIterator;
*/
public class ItemHandlerInventoryManipulator extends InventoryManipulator<IInvSlot> {
private final IItemHandler inv;
private final IItemHandler inv;
protected ItemHandlerInventoryManipulator(IItemHandler inv) {
this.inv = inv;
}
protected ItemHandlerInventoryManipulator(IItemHandler inv) {
this.inv = inv;
}
@Override
public Iterator<IInvSlot> iterator() {
return InventoryIterator.getIterable(inv).iterator();
}
@Override
public Iterator<IInvSlot> iterator() {
return InventoryIterator.getIterable(inv).iterator();
}
@Override
@Override
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
if (stack == null || stack.stackSize <= 0) {
if (stack == null || stack.stackSize <= 0) {
return null;
}
stack = stack.copy();
List<IInvSlot> filledSlots = new ArrayList<IInvSlot>(inv.getSlots());
List<IInvSlot> emptySlots = new ArrayList<IInvSlot>(inv.getSlots());
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
if (slot.canPutStackInSlot(stack)) {
if (slot.getStackInSlot() == null) {
stack = stack.copy();
List<IInvSlot> filledSlots = new ArrayList<>(inv.getSlots());
List<IInvSlot> emptySlots = new ArrayList<>(inv.getSlots());
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
if (slot.canPutStackInSlot(stack)) {
if (slot.getStackInSlot() == null) {
emptySlots.add(slot);
} else {
filledSlots.add(slot);
}
}
}
}
}
int injected = 0;
injected = tryPut(filledSlots, stack, injected, doAdd);
injected = tryPut(emptySlots, stack, injected, doAdd);
stack.stackSize -= injected;
if (stack.stackSize <= 0) {
int injected = 0;
injected = tryPut(filledSlots, stack, injected, doAdd);
injected = tryPut(emptySlots, stack, injected, doAdd);
stack.stackSize -= injected;
if (stack.stackSize <= 0) {
return null;
}
return stack;
}
return stack;
}
private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
if (injected >= stack.stackSize) {
private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
if (injected >= stack.stackSize) {
return injected;
}
for (IInvSlot slot : slots) {
ItemStack stackToInsert = stack.copy();
stackToInsert.stackSize = stack.stackSize - injected;
ItemStack remainder = inv.insertItem(slot.getIndex(), stackToInsert, !doAdd);
if (remainder == null) {
for (IInvSlot slot : slots) {
ItemStack stackToInsert = stack.copy();
stackToInsert.stackSize = stack.stackSize - injected;
ItemStack remainder = inv.insertItem(slot.getIndex(), stackToInsert, !doAdd);
if (remainder == null) {
return injected;
}
injected += remainder.stackSize;
if (injected >= stack.stackSize) {
injected += remainder.stackSize;
if (injected >= stack.stackSize) {
return injected;
}
}
return injected;
}
@Override
protected List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove) {
int amountNeeded = maxAmount;
List<ItemStack> outputList = new ArrayList<ItemStack>();
for (IInvSlot slot : this) {
if (amountNeeded <= 0) {
break;
}
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
ItemStack removed = inv.extractItem(slot.getIndex(), amountNeeded, !doRemove);
if (removed != null) {
amountNeeded -= removed.stackSize;
outputList.add(removed);
}
}
}
return outputList;
}
}
return injected;
}
}
@@ -10,13 +10,13 @@
******************************************************************************/
package forestry.core.inventory.manipulators;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import forestry.core.inventory.filters.IStackFilter;
import forestry.core.inventory.iterators.IExtInvSlot;
import forestry.core.inventory.iterators.InventoryIterator;
@@ -27,134 +27,99 @@ import forestry.core.utils.InventoryUtil;
*/
public class StandardInventoryManipulator extends InventoryManipulator<IExtInvSlot> {
private final IInventory inv;
private final IInventory inv;
protected StandardInventoryManipulator(IInventory inv) {
this.inv = inv;
}
protected StandardInventoryManipulator(IInventory inv) {
this.inv = inv;
}
@Override
public Iterator<IExtInvSlot> iterator() {
return InventoryIterator.getIterable(inv).iterator();
}
@Override
public Iterator<IExtInvSlot> iterator() {
return InventoryIterator.getIterable(inv).iterator();
}
@Override
@Override
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
if (stack == null || stack.stackSize <= 0) {
if (stack == null || stack.stackSize <= 0) {
return null;
}
stack = stack.copy();
List<IExtInvSlot> filledSlots = new ArrayList<IExtInvSlot>(inv.getSizeInventory());
List<IExtInvSlot> emptySlots = new ArrayList<IExtInvSlot>(inv.getSizeInventory());
for (IExtInvSlot slot : this) {
if (slot.canPutStackInSlot(stack)) {
stack = stack.copy();
List<IExtInvSlot> filledSlots = new ArrayList<>(inv.getSizeInventory());
List<IExtInvSlot> emptySlots = new ArrayList<>(inv.getSizeInventory());
for (IExtInvSlot slot : this) {
if (slot.canPutStackInSlot(stack)) {
if (slot.getStackInSlot() == null) {
emptySlots.add(slot);
} else {
filledSlots.add(slot);
}
}
}
}
int injected = 0;
injected = tryPut(filledSlots, stack, injected, doAdd);
injected = tryPut(emptySlots, stack, injected, doAdd);
stack.stackSize -= injected;
if (stack.stackSize <= 0) {
int injected = 0;
injected = tryPut(filledSlots, stack, injected, doAdd);
injected = tryPut(emptySlots, stack, injected, doAdd);
stack.stackSize -= injected;
if (stack.stackSize <= 0) {
return null;
}
return stack;
}
return stack;
}
private int tryPut(List<IExtInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
if (injected >= stack.stackSize) {
private int tryPut(List<IExtInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
if (injected >= stack.stackSize) {
return injected;
}
for (IExtInvSlot slot : slots) {
ItemStack stackInSlot = slot.getStackInSlot();
if (stackInSlot == null || InventoryUtil.isItemEqual(stackInSlot, stack)) {
int used = addToSlot(slot, stack, stack.stackSize - injected, doAdd);
if (used > 0) {
injected += used;
if (injected >= stack.stackSize) {
for (IExtInvSlot slot : slots) {
ItemStack stackInSlot = slot.getStackInSlot();
if (stackInSlot == null || InventoryUtil.isItemEqual(stackInSlot, stack)) {
int used = addToSlot(slot, stack, stack.stackSize - injected, doAdd);
if (used > 0) {
injected += used;
if (injected >= stack.stackSize) {
return injected;
}
}
}
}
return injected;
}
}
}
}
return injected;
}
/**
* @param available Amount we can move
* @return Return the number of items moved.
*/
private int addToSlot(IExtInvSlot slot, ItemStack stack, int available, boolean doAdd) {
int max = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
/**
* @param available Amount we can move
* @return Return the number of items moved.
*/
private int addToSlot(IExtInvSlot slot, ItemStack stack, int available, boolean doAdd) {
int max = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
ItemStack stackInSlot = slot.getStackInSlot();
if (stackInSlot == null) {
int wanted = Math.min(available, max);
if (doAdd) {
stackInSlot = stack.copy();
stackInSlot.stackSize = wanted;
slot.setStackInSlot(stackInSlot);
}
return wanted;
}
ItemStack stackInSlot = slot.getStackInSlot();
if (stackInSlot == null) {
int wanted = Math.min(available, max);
if (doAdd) {
stackInSlot = stack.copy();
stackInSlot.stackSize = wanted;
slot.setStackInSlot(stackInSlot);
}
return wanted;
}
if (!InventoryUtil.isItemEqual(stack, stackInSlot)) {
if (!InventoryUtil.isItemEqual(stack, stackInSlot)) {
return 0;
}
int wanted = max - stackInSlot.stackSize;
if (wanted <= 0) {
int wanted = max - stackInSlot.stackSize;
if (wanted <= 0) {
return 0;
}
if (wanted > available) {
if (wanted > available) {
wanted = available;
}
if (doAdd) {
stackInSlot.stackSize += wanted;
slot.setStackInSlot(stackInSlot);
}
return wanted;
}
@Override
protected List<ItemStack> removeItem(IStackFilter filter, int maxAmount, boolean doRemove) {
int amountNeeded = maxAmount;
List<ItemStack> outputList = new ArrayList<ItemStack>();
for (IExtInvSlot slot : this) {
if (amountNeeded <= 0) {
break;
}
ItemStack stack = slot.getStackInSlot();
if (stack != null && stack.stackSize > 0 && slot.canTakeStackFromSlot(stack) && filter.apply(stack)) {
ItemStack output = stack.copy();
if (output.stackSize >= amountNeeded) {
output.stackSize = amountNeeded;
if (doRemove) {
stack.stackSize -= amountNeeded;
if (stack.stackSize <= 0) {
stack = null;
}
slot.setStackInSlot(stack);
}
amountNeeded = 0;
outputList.add(output);
} else {
amountNeeded -= output.stackSize;
outputList.add(output);
if (doRemove) {
slot.setStackInSlot(null);
}
}
}
}
return outputList;
}
if (doAdd) {
stackInSlot.stackSize += wanted;
slot.setStackInSlot(stackInSlot);
}
return wanted;
}
}
@@ -10,11 +10,12 @@
******************************************************************************/
package forestry.core.inventory.wrappers;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import forestry.core.inventory.InventoryPlain;
import forestry.core.inventory.iterators.IExtInvSlot;
import forestry.core.inventory.iterators.InventoryIterator;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* Creates a deep copy of an existing IInventory.
@@ -26,40 +27,40 @@ import net.minecraft.item.ItemStack;
*/
public class InventoryCopy extends InvWrapperBase {
private InventoryPlain copy;
private final InventoryPlain copy;
public InventoryCopy(IInventory original) {
super(original);
this.copy = new InventoryPlain(original.getSizeInventory());
for (IExtInvSlot slot : InventoryIterator.getIterable(original)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
copy.setInventorySlotContents(slot.getIndex(), stack.copy());
}
}
}
public InventoryCopy(IInventory original) {
super(original);
this.copy = new InventoryPlain(original.getSizeInventory());
for (IExtInvSlot slot : InventoryIterator.getIterable(original)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
copy.setInventorySlotContents(slot.getIndex(), stack.copy());
}
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
copy.setInventorySlotContents(slot, itemstack);
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
copy.setInventorySlotContents(slot, itemstack);
}
@Override
public ItemStack getStackInSlot(int slot) {
return copy.getStackInSlot(slot);
}
@Override
public ItemStack getStackInSlot(int slot) {
return copy.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return copy.decrStackSize(slot, amount);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return copy.decrStackSize(slot, amount);
}
@Override
public ItemStack removeStackFromSlot(int slot) {
return copy.removeStackFromSlot(slot);
}
@Override
public ItemStack removeStackFromSlot(int slot) {
return copy.removeStackFromSlot(slot);
}
@Override
@Override
public void markDirty() {
}
}
}
@@ -22,70 +22,70 @@ import net.minecraft.item.ItemStack;
*/
public class InventoryMapper extends InvWrapperBase implements IInventory {
private final IInventory inv;
private final int start;
private final int size;
private int stackSizeLimit = -1;
private final IInventory inv;
private final int start;
private final int size;
private int stackSizeLimit = -1;
public InventoryMapper(IInventory inv) {
this(inv, 0, inv.getSizeInventory(), true);
}
public InventoryMapper(IInventory inv) {
this(inv, 0, inv.getSizeInventory(), true);
}
public InventoryMapper(IInventory inv, boolean checkItems) {
this(inv, 0, inv.getSizeInventory(), checkItems);
}
public InventoryMapper(IInventory inv, boolean checkItems) {
this(inv, 0, inv.getSizeInventory(), checkItems);
}
/**
* Creates a new InventoryMapper
*
* @param inv The backing inventory
* @param start The starting index
* @param size The size of the new inventory, take care not to exceed the
* end of the backing inventory
*/
public InventoryMapper(IInventory inv, int start, int size) {
this(inv, start, size, true);
}
/**
* Creates a new InventoryMapper
*
* @param inv The backing inventory
* @param start The starting index
* @param size The size of the new inventory, take care not to exceed the
* end of the backing inventory
*/
public InventoryMapper(IInventory inv, int start, int size) {
this(inv, start, size, true);
}
public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) {
super(inv, checkItems);
this.inv = inv;
this.start = start;
this.size = size;
}
public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) {
super(inv, checkItems);
this.inv = inv;
this.start = start;
this.size = size;
}
@Override
public int getSizeInventory() {
return size;
}
@Override
public int getSizeInventory() {
return size;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inv.getStackInSlot(start + slot);
}
@Override
public ItemStack getStackInSlot(int slot) {
return inv.getStackInSlot(start + slot);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return inv.decrStackSize(start + slot, amount);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return inv.decrStackSize(start + slot, amount);
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
inv.setInventorySlotContents(start + slot, itemstack);
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
inv.setInventorySlotContents(start + slot, itemstack);
}
public void setStackSizeLimit(int limit) {
stackSizeLimit = limit;
}
public void setStackSizeLimit(int limit) {
stackSizeLimit = limit;
}
@Override
public int getInventoryStackLimit() {
return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit();
}
@Override
public int getInventoryStackLimit() {
return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return !checkItems() || inv.isItemValidForSlot(start + slot, stack);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return !checkItems() || inv.isItemValidForSlot(start + slot, stack);
}
}
@@ -22,32 +22,32 @@ import net.minecraft.util.EnumFacing;
*/
public class SidedInventoryMapper extends InvWrapperBase implements ISidedInventory {
private final ISidedInventory inv;
private final EnumFacing side;
private final ISidedInventory inv;
private final EnumFacing side;
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side) {
this(inv, side, true);
}
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side) {
this(inv, side, true);
}
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side, boolean checkItems) {
super(inv, checkItems);
this.inv = inv;
this.side = side;
}
public SidedInventoryMapper(ISidedInventory inv, EnumFacing side, boolean checkItems) {
super(inv, checkItems);
this.inv = inv;
this.side = side;
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
return inv.getSlotsForFace(side);
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
return inv.getSlotsForFace(side);
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing s) {
return !checkItems() || inv.canInsertItem(slot, stack, side);
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing s) {
return !checkItems() || inv.canInsertItem(slot, stack, side);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing s) {
return !checkItems() || inv.canExtractItem(slot, stack, side);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing s) {
return !checkItems() || inv.canExtractItem(slot, stack, side);
}
}
@@ -26,7 +26,6 @@ public class ItemCraftingMaterial extends ItemForestry {
private final String[] definition = new String[]{"pulsatingDust", "pulsatingMesh", "silkWisp", "wovenSilk", "dissipationCharge", "iceShard", "scentedPaneling", "camouflagedPaneling" };
public ItemCraftingMaterial() {
super();
setMaxDamage(0);
setHasSubtypes(true);
}
@@ -32,7 +32,6 @@ import forestry.core.fluids.PipetteContents;
public class ItemPipette extends ItemForestry implements IToolPipette {
public ItemPipette() {
super();
setMaxStackSize(1);
setFull3D();
}
@@ -26,7 +26,6 @@ import buildcraft.api.tools.IToolWrench;
public class ItemWrench extends ItemForestry implements IToolWrench {
public ItemWrench() {
super();
setHarvestLevel("wrench", 0);
}
@@ -11,7 +11,6 @@
package forestry.core.models;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@@ -28,7 +27,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.model.IBakedModel;
@@ -79,8 +77,7 @@ public class ModelCrate extends BlankItemModel {
MODEL_COMPASS = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 15);
MODEL_CLOCK = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 16);
} catch (IOException e) {
Log.error("Failed to init the crate model.");
e.printStackTrace();
Log.error("Failed to init the crate model.", e);
}
}
@@ -176,6 +173,7 @@ public class ModelCrate extends BlankItemModel {
try {
model.parent = loadModel(model.getParentLocation());
} catch (IOException e) {
Log.error("Failed to load model.", e);
}
}
}
@@ -202,16 +200,6 @@ public class ModelCrate extends BlankItemModel {
}
}
private Function<ResourceLocation, TextureAtlasSprite> textureGetter = new DefaultTextureGetter();
/**
* Bake the crate model;
*/
/*private IFlexibleBakedModel getModelCrate() {
IFlexibleBakedModel flexModel = getModel(new ItemStack(PluginStorage.items.crate, 1, 1));
return crateModel.bake(crateModel.getDefaultState(), flexModel.getFormat(), textureGetter);
}*/
/**
* Bake the crated model
*/
@@ -40,8 +40,8 @@ public class ModelManager implements IModelManager {
private static final ModelManager instance = new ModelManager();
private static final ArrayList<BlockModelIndex> customBlockModels = new ArrayList<BlockModelIndex>();
private static final ArrayList<ModelIndex> customModels = new ArrayList<ModelIndex>();
private static final ArrayList<BlockModelIndex> customBlockModels = new ArrayList<>();
private static final ArrayList<ModelIndex> customModels = new ArrayList<>();
static {
ForestryAPI.modelManager = instance;
@@ -76,7 +76,7 @@ public class TRSRBakedModel implements IFlexibleBakedModel {
}
}
//faces.put(face, builder.build());
faces.put(face, ImmutableList.<BakedQuad>of());
faces.put(face, ImmutableList.of());
}
// general quads
@@ -42,9 +42,9 @@ public class ModelBakerModel implements IModelBakerModel {
private float[] scale = getDefaultScale();
public ModelBakerModel() {
general = new ArrayList<BakedQuad>();
general = new ArrayList<>();
for (EnumFacing f : EnumFacing.VALUES) {
faces[f.ordinal()] = new ArrayList<BakedQuad>();
faces[f.ordinal()] = new ArrayList<>();
}
formate = DefaultVertexFormats.BLOCK;
isGui3d = true;
@@ -13,6 +13,8 @@ package forestry.core.multiblock;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -98,6 +100,7 @@ public abstract class MultiblockControllerForestry extends MultiblockControllerB
}
/* INVENTORY */
@Nonnull
public IInventoryAdapter getInternalInventory() {
return FakeInventoryAdapter.instance();
}
@@ -70,7 +70,7 @@ public class MultiblockWorldRegistry {
* Called before Tile Entities are ticked in the world. Run game logic.
*/
public void tickStart() {
if (controllers.size() > 0) {
if (!controllers.isEmpty()) {
for (IMultiblockControllerInternal controller : controllers) {
if (controller.getWorld() == worldObj && controller.getWorld().isRemote == worldObj.isRemote) {
if (controller.isEmpty()) {
@@ -95,7 +95,7 @@ public class MultiblockWorldRegistry {
// Merge pools - sets of adjacent machines which should be merged later on in processing
List<Set<IMultiblockControllerInternal>> mergePools = null;
if (orphanedParts.size() > 0) {
if (!orphanedParts.isEmpty()) {
Set<IMultiblockComponent> orphansToProcess = null;
// Keep the synchronized block small. We can't iterate over orphanedParts directly
@@ -103,13 +103,13 @@ public class MultiblockWorldRegistry {
// is not chunk-safe on the client, because Minecraft is stupid.
// It's possible to polyfill this, but the polyfill is too slow for comfort.
synchronized (orphanedPartsMutex) {
if (orphanedParts.size() > 0) {
if (!orphanedParts.isEmpty()) {
orphansToProcess = orphanedParts;
orphanedParts = new HashSet<>();
}
}
if (orphansToProcess != null && orphansToProcess.size() > 0) {
if (orphansToProcess != null && !orphansToProcess.isEmpty()) {
Set<IMultiblockControllerInternal> compatibleControllers;
// Process orphaned blocks
@@ -133,7 +133,7 @@ public class MultiblockWorldRegistry {
// THIS IS THE ONLY PLACE WHERE PARTS ATTACH TO MACHINES
// Try to attach to a neighbor's master controller
compatibleControllers = attachToNeighbors(orphan);
if (compatibleControllers.size() == 0) {
if (compatibleControllers.isEmpty()) {
// FOREVER ALONE! Create and register a new controller.
// THIS IS THE ONLY PLACE WHERE NEW CONTROLLERS ARE CREATED.
MultiblockLogic logic = (MultiblockLogic) orphan.getMultiblockLogic();
@@ -178,7 +178,7 @@ public class MultiblockWorldRegistry {
}
}
if (mergePools != null && mergePools.size() > 0) {
if (mergePools != null && !mergePools.isEmpty()) {
// Process merges - any machines that have been marked for merge should be merged
// into the "master" machine.
// To do this, we combine lists of machines that are touching one another and therefore
@@ -211,7 +211,7 @@ public class MultiblockWorldRegistry {
// Process splits and assembly
// Any controllers which have had parts removed must be checked to see if some parts are no longer
// physically connected to their master.
if (dirtyControllers.size() > 0) {
if (!dirtyControllers.isEmpty()) {
for (IMultiblockControllerInternal controller : dirtyControllers) {
if (controller == null) {
continue;
@@ -229,7 +229,7 @@ public class MultiblockWorldRegistry {
addDeadController(controller);
}
if (newlyDetachedParts.size() > 0) {
if (!newlyDetachedParts.isEmpty()) {
// Controller has shed some parts - add them to the detached list for delayed processing
detachedParts.addAll(newlyDetachedParts);
}
@@ -239,7 +239,7 @@ public class MultiblockWorldRegistry {
}
// Unregister dead controllers
if (deadControllers.size() > 0) {
if (!deadControllers.isEmpty()) {
for (IMultiblockControllerInternal controller : deadControllers) {
// Go through any controllers which have marked themselves as potentially dead.
// Validate that they are empty/dead, then unregister them.
@@ -4,7 +4,10 @@ import java.util.Collections;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -17,7 +20,7 @@ public class EmptyStateMapper implements IStateMapper {
}
@Override
public Map putStateModelLocations(Block block) {
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
return Collections.emptyMap();
}
@@ -10,17 +10,17 @@
******************************************************************************/
package forestry.core.render;
import forestry.core.blocks.BlockBase;
import forestry.core.blocks.IBlockType;
import forestry.core.blocks.IMachinePropertiesTesr;
import forestry.core.proxy.Proxies;
import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import forestry.core.blocks.BlockBase;
import forestry.core.blocks.IBlockType;
import forestry.core.blocks.IMachinePropertiesTesr;
import forestry.core.proxy.Proxies;
public class MachineParticleCallback<P extends Enum<P> & IBlockType & IStringSerializable> extends ParticleHelper.DefaultCallback<BlockBase> {
private final PropertyEnum<P> TYPE;
@@ -141,20 +141,4 @@ public class ParticleHelper {
fx.setParticleIcon(Proxies.common.getClientInstance().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state));
}
}
public static class TexturedCallback extends ParticleHelper.DefaultCallback{
private final String textureLocation;
public TexturedCallback(Block block, String textureLocation) {
super(block);
this.textureLocation = textureLocation;
}
@Override
protected void setTexture(EntityDiggingFX fx, BlockPos pos, IBlockState state) {
fx.setParticleIcon(Proxies.common.getClientInstance().getTextureMapBlocks().getAtlasSprite(textureLocation));
}
}
}
@@ -20,15 +20,14 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.ISpriteProvider;
import forestry.api.core.ISpriteRegister;
import forestry.api.core.IStateMapperRegister;
import forestry.api.core.ITextureManager;
import forestry.core.proxy.Proxies;
@@ -10,10 +10,13 @@
******************************************************************************/
package forestry.core.tiles;
import javax.annotation.Nonnull;
import forestry.core.fluids.ITankManager;
public interface ILiquidTankTile extends ILocatable {
@Nonnull
ITankManager getTankManager();
}
@@ -194,7 +194,7 @@ public class GeneticsUtil {
}
public static int getResearchComplexity(IAlleleSpecies species, IChromosomeType speciesChromosome) {
return 1 + getGeneticAdvancement(species, new HashSet<IAlleleSpecies>(), speciesChromosome);
return 1 + getGeneticAdvancement(species, new HashSet<>(), speciesChromosome);
}
private static int getGeneticAdvancement(IAlleleSpecies species, Set<IAlleleSpecies> exclude, IChromosomeType speciesChromosome) {
@@ -39,7 +39,6 @@ import forestry.core.inventory.filters.ArrayStackFilter;
import forestry.core.inventory.filters.IStackFilter;
import forestry.core.inventory.filters.StandardStackFilters;
import forestry.core.inventory.iterators.IExtInvSlot;
import forestry.core.inventory.iterators.IInvSlot;
import forestry.core.inventory.iterators.InventoryIterator;
import forestry.core.inventory.manipulators.InventoryManipulator;
import forestry.core.inventory.wrappers.InventoryCopy;
@@ -78,12 +77,12 @@ public abstract class InventoryUtil {
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
}
public static ItemStack makeSafe(ItemStack stack) {
if (stack.stackSize <= 0) {
public static ItemStack makeSafe(ItemStack stack) {
if (stack.stackSize <= 0) {
return null;
}
return stack;
}
return stack;
}
/**
* A more robust item comparison function.
@@ -166,21 +165,21 @@ public abstract class InventoryUtil {
return false;
}
/**
* Returns true if the item is equal to any one of several possible matches.
*
* @param stack the ItemStack to test
* @param matches the ItemStacks to test against
* @return true if a match is found
*/
public static boolean isItemEqual(ItemStack stack, Collection<ItemStack> matches) {
for (ItemStack match : matches) {
if (isItemEqual(stack, match)) {
/**
* Returns true if the item is equal to any one of several possible matches.
*
* @param stack the ItemStack to test
* @param matches the ItemStacks to test against
* @return true if a match is found
*/
public static boolean isItemEqual(ItemStack stack, Collection<ItemStack> matches) {
for (ItemStack match : matches) {
if (isItemEqual(stack, match)) {
return true;
}
}
return false;
}
}
return false;
}
/**
* Places an ItemStack in a destination IInventory. Will attempt to move as
@@ -215,23 +214,6 @@ public abstract class InventoryUtil {
}
return false;
}
/**
* Returns true if the inventory contains the specified item.
*
* @param inv the inventory The inventory to check
* @param item The ItemStack to look for
* @return true is exists
*/
public static boolean containsItem(IInventory inv, ItemStack item) {
for (IInvSlot slot : InventoryIterator.getIterable(inv)) {
ItemStack stack = slot.getStackInSlot();
if (stack != null && isItemEqual(stack, item)) {
return true;
}
}
return false;
}
/**
* Attempts to move an ItemStack from one inventory to another.
@@ -484,8 +484,7 @@ public abstract class ItemStackUtil {
Item item = stack.getItem();
if (item != null) {
int meta = stack.getMeta();
ItemStack itemStack = new ItemStack(item, 1, meta);
return itemStack;
return new ItemStack(item, 1, meta);
}
return null;
}
@@ -86,7 +86,7 @@ public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStrea
}
public ItemStack getRecipeOutput() {
if (recipeOutputs.size() == 0) {
if (recipeOutputs.isEmpty()) {
return null;
} else {
return recipeOutputs.get(selectedRecipe);
@@ -74,7 +74,7 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory {
private void setResults(Map<ItemStack, Float> outputs, GuiItemStackGroup guiItemStacks) {
Set<Entry<ItemStack, Float>> entrySet = outputs.entrySet();
if (entrySet.size() == 0) {
if (entrySet.isEmpty()) {
return;
}
PriorityQueue<Entry<ItemStack, Float>> sortByChance = new PriorityQueue<>(entrySet.size(), highestChanceComparator);
@@ -95,7 +95,7 @@ public class FabricatorRecipeCategory extends ForestryRecipeCategory {
for (IFabricatorSmeltingRecipe smelting : FabricatorSmeltingRecipeManager.recipes) {
Fluid fluid = smelting.getProduct().getFluid();
if (!smeltingInputs.containsKey(fluid)) {
smeltingInputs.put(fluid, new ArrayList<IFabricatorSmeltingRecipe>());
smeltingInputs.put(fluid, new ArrayList<>());
}
smeltingInputs.get(fluid).add(smelting);
}
@@ -381,7 +381,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
}
// Grab new items from stash
for (int i = 0; i < (slotsToShift.size() > 0 ? shiftedSlots : 2); i++) {
for (int i = 0; i < (!slotsToShift.isEmpty() ? shiftedSlots : 2); i++) {
int resourceSlot = getNextResourceSlot(0, InventoryMoistener.SLOT_RESERVOIR_1);
// Stop if no resources are available
if (resourceSlot < 0) {
@@ -101,39 +101,39 @@ public class PluginFarming extends BlankForestryPlugin {
public void preInit() {
MinecraftForge.EVENT_BUS.register(this);
Farmables.farmables.put("farmArboreal", new ArrayList<IFarmable>());
Farmables.farmables.put("farmArboreal", new ArrayList<>());
Farmables.farmables.get("farmArboreal").add(new FarmableVanillaSapling());
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) {
Farmables.farmables.get("farmArboreal").add(new FarmableGE());
}
Farmables.farmables.put("farmOrchard", new ArrayList<IFarmable>());
Farmables.farmables.put("farmOrchard", new ArrayList<>());
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.wheat, 7));
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.potatoes, 7));
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.carrots, 7));
Farmables.farmables.put("farmShroom", new ArrayList<IFarmable>());
Farmables.farmables.put("farmShroom", new ArrayList<>());
Farmables.farmables.get("farmShroom").add(new FarmableVanillaMushroom(Blocks.brown_mushroom, 0));
Farmables.farmables.get("farmShroom").add(new FarmableVanillaMushroom(Blocks.red_mushroom, 0));
Farmables.farmables.put("farmWheat", new ArrayList<IFarmable>());
Farmables.farmables.put("farmWheat", new ArrayList<>());
Farmables.farmables.get("farmWheat").add(new FarmableGenericCrop(new ItemStack(Items.wheat_seeds), Blocks.wheat, 7));
Farmables.farmables.put("farmGourd", new ArrayList<IFarmable>());
Farmables.farmables.put("farmGourd", new ArrayList<>());
Farmables.farmables.get("farmGourd").add(
new FarmableGourd(new ItemStack(Items.pumpkin_seeds), new ItemStack(Blocks.pumpkin_stem), new ItemStack(Blocks.pumpkin)));
Farmables.farmables.get("farmGourd").add(new FarmableGourd(new ItemStack(Items.melon_seeds), new ItemStack(Blocks.melon_stem), new ItemStack(Blocks.melon_block)));
Farmables.farmables.put("farmInfernal", new ArrayList<IFarmable>());
Farmables.farmables.put("farmInfernal", new ArrayList<>());
Farmables.farmables.get("farmInfernal").add(new FarmableGenericCrop(new ItemStack(Items.nether_wart), Blocks.nether_wart, 3));
Farmables.farmables.put("farmPoales", new ArrayList<IFarmable>());
Farmables.farmables.put("farmPoales", new ArrayList<>());
Farmables.farmables.get("farmPoales").add(new FarmableStacked(Blocks.reeds, 3, 0));
Farmables.farmables.put("farmSucculentes", new ArrayList<IFarmable>());
Farmables.farmables.put("farmSucculentes", new ArrayList<>());
Farmables.farmables.get("farmSucculentes").add(new FarmableStacked(Blocks.cactus, 3, 0));
Farmables.farmables.put("farmVegetables", new ArrayList<IFarmable>());
Farmables.farmables.put("farmVegetables", new ArrayList<>());
Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.potato), Blocks.potatoes, 7));
Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.carrot), Blocks.carrots, 7));
@@ -1,10 +1,14 @@
package forestry.farming.models;
import javax.annotation.Nonnull;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.property.IExtendedBlockState;
import forestry.api.core.IModelBaker;
import forestry.core.models.ModelBlockOverlay;
import forestry.farming.blocks.BlockFarm;
@@ -18,7 +22,7 @@ public class ModelFarmBlock extends ModelBlockOverlay<BlockFarm> {
}
@Override
public void bakeInventoryBlock(BlockFarm blockFarm, ItemStack item, IModelBaker baker) {
public void bakeInventoryBlock(@Nonnull BlockFarm blockFarm, @Nonnull ItemStack item, @Nonnull IModelBaker baker) {
if (blockFarm == null) {
return;
}
@@ -32,7 +36,7 @@ public class ModelFarmBlock extends ModelBlockOverlay<BlockFarm> {
}
@Override
public void bakeWorldBlock(BlockFarm blockFarm, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) {
public void bakeWorldBlock(@Nonnull BlockFarm blockFarm, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IExtendedBlockState stateExtended, @Nonnull IModelBaker baker) {
TileFarm farm = (TileFarm) world.getTileEntity(pos);
@@ -500,8 +500,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
if (stage == Stage.HARVEST) {
Collection<ICrop> harvested = harvestTargets(farmTargets, logic, farmListeners);
farmWorkStatus.didWork = harvested.size() > 0;
if (harvested.size() > 0) {
farmWorkStatus.didWork = !harvested.isEmpty();
if (!harvested.isEmpty()) {
pendingCrops.addAll(harvested);
harvestProvider = logic;
}
@@ -684,7 +684,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
if (farmTargets != null) {
for (FarmTarget target : farmTargets) {
Collection<ICrop> harvested = harvestTarget(target, logic, farmListeners);
if (harvested.size() > 0) {
if (!harvested.isEmpty()) {
return harvested;
}
}
@@ -696,7 +696,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
private static Collection<ICrop> harvestTarget(FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
BlockPos pos = new BlockPos(target.getStart().getX(), target.getStart().getX() + target.getYOffset(), target.getStart().getZ());
Collection<ICrop> harvested = logic.harvest(pos, target.getDirection(), target.getExtent());
if (harvested == null || harvested.size() == 0) {
if (harvested == null || harvested.isEmpty()) {
return Collections.emptyList();
}
@@ -30,7 +30,7 @@ public class FarmingTriggers {
public static List<ITriggerExternal> allExternalTriggers;
public static void initialize() {
allExternalTriggers = Arrays.<ITriggerExternal>asList(
allExternalTriggers = Arrays.asList(
lowResourceLiquid50 = new TriggerLowLiquid("lowLiquid.50", 0.5f),
lowResourceLiquid25 = new TriggerLowLiquid("lowLiquid.25", 0.25f),
lowSoil128 = new TriggerLowSoil(128),
@@ -43,11 +43,6 @@ public class TriggerLowSoil extends Trigger {
return 1;
}
@Override
public int minParameters() {
return 0;
}
/**
* Return true if the tile given in parameter activates the trigger, given
* the parameters.
@@ -10,34 +10,31 @@
******************************************************************************/
package forestry.greenhouse;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import forestry.api.core.ICamouflageHandler;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IGreenhouseController;
import forestry.greenhouse.blocks.BlockGreenhouseType;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EventHandlerGreenhouse {
@SubscribeEvent
public void onCamouflageChance(CamouflageChangeEvent event){
public void onCamouflageChance(CamouflageChangeEvent event) {
ICamouflageHandler handler = event.camouflageHandler;
IGreenhouseController controller = null;
if(handler instanceof IGreenhouseController){
if (handler instanceof IGreenhouseController) {
controller = (IGreenhouseController) handler;
}
if(handler instanceof IGreenhouseComponent){
if (handler instanceof IGreenhouseComponent) {
IGreenhouseComponent component = (IGreenhouseComponent) handler;
controller = component.getMultiblockLogic().getController();
}
if(controller != null){
if (controller != null) {
controller.onChange(EnumGreenhouseEventType.CAMOUFLAGE, event);
}
}
@@ -14,12 +14,13 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.minecraft.world.World;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.greenhouse.IGreenhouseState;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IMultiblockComponent;
import net.minecraft.world.World;
public class FakeGreenhouseState implements IGreenhouseState {
@@ -10,59 +10,59 @@
******************************************************************************/
package forestry.greenhouse;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import forestry.api.core.EnumCamouflageType;
import forestry.api.greenhouse.IGreenhouseAccess;
import forestry.core.utils.Log;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
public class GreenhouseAccess implements IGreenhouseAccess {
private final Map<ItemStack, Float> greenhouseGlass = new HashMap();
private final Map<EnumCamouflageType, List<ItemStack>> camouflageBlockBlacklist = new EnumMap(EnumCamouflageType.class);
private final Map<ItemStack, Float> greenhouseGlasses = new HashMap<>();
private final Map<EnumCamouflageType, List<ItemStack>> camouflageBlockBlacklist = new EnumMap<>(EnumCamouflageType.class);
public GreenhouseAccess() {
for(EnumCamouflageType type : EnumCamouflageType.VALUES){
camouflageBlockBlacklist.put(type, new ArrayList());
for (EnumCamouflageType type : EnumCamouflageType.VALUES) {
camouflageBlockBlacklist.put(type, new ArrayList<>());
}
}
@Override
public void registerGreenhouseGlass(@Nonnull ItemStack glass, float lightTransmittance) {
if(glass == null || glass.getItem() == null){
if (glass == null || glass.getItem() == null) {
Log.error("Fail to register greenhouse glass, because it is null");
return;
}
Block block = Block.getBlockFromItem(glass.getItem());
if(block == null || block.isOpaqueCube()){
if (block == null || block.isOpaqueCube()) {
Log.error("Fail to register greenhouse glass: " + block + ".");
return;
}
for(ItemStack greenhouseGlass : greenhouseGlass.keySet()){
if(greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)){
for (ItemStack greenhouseGlass : greenhouseGlasses.keySet()) {
if (greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)) {
Log.error("Fail to register greenhouse glass, because it is already registered: " + glass + ".");
return;
}
}
greenhouseGlass.put(glass, lightTransmittance);
greenhouseGlasses.put(glass, lightTransmittance);
}
@Override
public float getGreenhouseGlassLightTransmittance(ItemStack glass) {
if(glass == null || glass.getItem() == null || Block.getBlockFromItem(glass.getItem()) == null) {
public float getGreenhouseGlassLightTransmittance(@Nonnull ItemStack glass) {
if (glass == null || glass.getItem() == null || Block.getBlockFromItem(glass.getItem()) == null) {
return 0.5F;
}
for(Map.Entry<ItemStack, Float> greenhouseGlassEntry : greenhouseGlass.entrySet()){
for (Map.Entry<ItemStack, Float> greenhouseGlassEntry : greenhouseGlasses.entrySet()) {
ItemStack greenhouseGlass = greenhouseGlassEntry.getKey();
if(greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)){
if (greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)) {
return greenhouseGlassEntry.getValue();
}
}
@@ -71,11 +71,11 @@ public class GreenhouseAccess implements IGreenhouseAccess {
@Override
public boolean isGreenhouseGlass(@Nonnull ItemStack glass) {
if(glass == null || glass.getItem() == null || Block.getBlockFromItem(glass.getItem()) == null) {
if (glass == null || glass.getItem() == null || Block.getBlockFromItem(glass.getItem()) == null) {
return false;
}
for(ItemStack greenhouseGlass : greenhouseGlass.keySet()){
if(greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)){
for (ItemStack greenhouseGlass : greenhouseGlasses.keySet()) {
if (greenhouseGlass.getItem() == glass.getItem() && greenhouseGlass.getItemDamage() == glass.getItemDamage() && ItemStack.areItemStackTagsEqual(glass, greenhouseGlass)) {
return true;
}
}
@@ -84,17 +84,17 @@ public class GreenhouseAccess implements IGreenhouseAccess {
@Override
public void addToCamouflageBlockBlackList(@Nonnull EnumCamouflageType type, @Nonnull ItemStack camouflageBlock) {
if(camouflageBlock == null || camouflageBlock.getItem() == null){
if (camouflageBlock == null || camouflageBlock.getItem() == null) {
Log.error("Fail to add camouflage block item to the black list, because it is null");
return;
}
Block block = Block.getBlockFromItem(camouflageBlock.getItem());
if(block == null){
if (block == null) {
Log.error("Fail to add camouflage block item to the black list: because it has no block.");
return;
}
for(ItemStack camouflageBlacklisted : camouflageBlockBlacklist.get(type)){
if(camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)){
for (ItemStack camouflageBlacklisted : camouflageBlockBlacklist.get(type)) {
if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) {
Log.error("Fail to add camouflage block item to the black list, because it is already registered: " + camouflageBlock + ".");
return;
}
@@ -104,11 +104,11 @@ public class GreenhouseAccess implements IGreenhouseAccess {
@Override
public boolean isOnCamouflageBlockBlackList(@Nonnull EnumCamouflageType type, @Nonnull ItemStack camouflageBlock) {
if(camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null) {
if (camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null) {
return false;
}
for(ItemStack camouflageBlacklisted : camouflageBlockBlacklist.get(type)){
if(camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)){
for (ItemStack camouflageBlacklisted : camouflageBlockBlacklist.get(type)) {
if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) {
return true;
}
}
@@ -10,24 +10,25 @@
******************************************************************************/
package forestry.greenhouse;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import forestry.api.greenhouse.IGreenhouseHelper;
import forestry.api.greenhouse.IGreenhouseState;
import forestry.api.greenhouse.IInternalBlock;
import forestry.core.multiblock.IMultiblockControllerInternal;
import forestry.core.multiblock.MultiblockRegistry;
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class GreenhouseHelper implements IGreenhouseHelper {
@Override
public IGreenhouseState getGreenhouseState(World world, BlockPos pos) {
if(MultiblockRegistry.getControllersFromWorld(world) != null){
for(IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)){
if(controllerInternal instanceof IGreenhouseControllerInternal){
if(controllerInternal.isAssembled()){
if(isPosiotionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)){
if (MultiblockRegistry.getControllersFromWorld(world) != null) {
for (IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)) {
if (controllerInternal instanceof IGreenhouseControllerInternal) {
if (controllerInternal.isAssembled()) {
if (isPosiotionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)) {
return ((IGreenhouseControllerInternal) controllerInternal).createState();
}
}
@@ -37,9 +38,9 @@ public class GreenhouseHelper implements IGreenhouseHelper {
return null;
}
private static boolean isPosiotionInGreenhouse(IGreenhouseControllerInternal controller, BlockPos pos){
for(IInternalBlock internalBlock : controller.getInternalBlocks()){
if(internalBlock.getPos().equals(pos)){
private static boolean isPosiotionInGreenhouse(IGreenhouseControllerInternal controller, BlockPos pos) {
for (IInternalBlock internalBlock : controller.getInternalBlocks()) {
if (internalBlock.getPos().equals(pos)) {
return true;
}
}
@@ -13,13 +13,14 @@ package forestry.greenhouse;
import java.util.Collection;
import java.util.List;
import net.minecraft.world.World;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.greenhouse.IGreenhouseState;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.greenhouse.multiblock.GreenhouseController;
import net.minecraft.world.World;
public final class GreenhouseState implements IGreenhouseState {
@@ -10,6 +10,13 @@
******************************************************************************/
package forestry.greenhouse;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.registry.GameRegistry;
import forestry.api.core.ForestryAPI;
import forestry.api.greenhouse.GreenhouseManager;
import forestry.api.greenhouse.IGreenhouseAccess;
@@ -40,11 +47,6 @@ import forestry.greenhouse.tiles.TileGreenhouseValve;
import forestry.plugins.BlankForestryPlugin;
import forestry.plugins.ForestryPlugin;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.registry.GameRegistry;
@ForestryPlugin(pluginID = ForestryPluginUids.GREENHOUSE, name = "Greenhouse", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.greenhouse.description")
public class PluginGreenhouse extends BlankForestryPlugin {
@@ -192,13 +194,13 @@ public class PluginGreenhouse extends BlankForestryPlugin {
GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain");
GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor");
GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch");
if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch");
}
}
@Override
public void preInit(){
public void preInit() {
MinecraftForge.EVENT_BUS.register(new EventHandlerGreenhouse());
IGreenhouseAccess greenhouseAccess = GreenhouseManager.greenhouseAccess;
@@ -70,7 +70,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
public static final PropertyEnum<State> STATE = PropertyEnum.create("state", State.class);
public static enum State implements IStringSerializable {
public enum State implements IStringSerializable {
ON, OFF;
@Override
@@ -82,16 +82,16 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
public static Map<BlockGreenhouseType, BlockGreenhouse> create() {
Map<BlockGreenhouseType, BlockGreenhouse> blockMap = new EnumMap<>(BlockGreenhouseType.class);
for (final BlockGreenhouseType type : BlockGreenhouseType.VALUES) {
if(type == BlockGreenhouseType.BUTTERFLY_HATCH){
if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
if (type == BlockGreenhouseType.BUTTERFLY_HATCH) {
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
continue;
}
}
BlockGreenhouse block;
if(type == BlockGreenhouseType.DOOR){
if (type == BlockGreenhouseType.DOOR) {
block = new BlockGreenhouseDoor();
}else{
} else {
block = new BlockGreenhouse() {
@Nonnull
@Override
@@ -109,45 +109,45 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
super(Material.rock);
BlockGreenhouseType greenhouseType = getGreenhouseType();
IBlockState defaultState = this.blockState.getBaseState();
if(greenhouseType.activatable && greenhouseType != BlockGreenhouseType.SPRINKLER){
if (greenhouseType.activatable && greenhouseType != BlockGreenhouseType.SPRINKLER) {
defaultState = defaultState.withProperty(STATE, State.OFF);
}
setDefaultState(defaultState);
setHardness(1.0f);
setHarvestLevel("pickaxe", 0);
if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)){
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) {
setCreativeTab(Tabs.tabAgriculture);
}else{
} else {
setCreativeTab(CreativeTabForestry.tabForestry);
}
}
@Override
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos){
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
this.setBlockBoundsBasedOnState(worldIn, pos);
}
return super.getSelectedBoundingBox(worldIn, pos);
}
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) {
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
this.setBlockBoundsBasedOnState(worldIn, pos);
}
return super.getSelectedBoundingBox(worldIn, pos);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state){
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
this.setBlockBoundsBasedOnState(worldIn, pos);
}
return super.getCollisionBoundingBox(worldIn, pos, state);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
this.setBlockBoundsBasedOnState(worldIn, pos);
}
return super.getCollisionBoundingBox(worldIn, pos, state);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos){
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
setBlockBounds(0.3125F, 0.25F, 0.3125F, 0.6875F, 1F, 0.6875F);
}else{
super.setBlockBoundsBasedOnState(worldIn, pos);
}
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
setBlockBounds(0.3125F, 0.25F, 0.3125F, 0.6875F, 1F, 0.6875F);
} else {
super.setBlockBoundsBasedOnState(worldIn, pos);
}
}
@Override
public int getMetaFromState(IBlockState state) {
@@ -156,29 +156,29 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
if(getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.DOOR){
if (getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.DOOR) {
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
. withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
}
return super.getExtendedState(state, world, pos);
}
@Override
protected BlockState createBlockState() {
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
return new ExtendedBlockState(this, new IProperty[]{ Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty });
}else if(getGreenhouseType().activatable){
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
return new ExtendedBlockState(this, new IProperty[]{Properties.StaticProperty}, new IUnlistedProperty[]{Properties.AnimationProperty});
} else if (getGreenhouseType().activatable) {
return new ExtendedBlockState(this, new IProperty[]{STATE}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
}else{
} else {
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
}
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
return state.withProperty(Properties.StaticProperty, true);
}else{
} else {
return super.getActualState(state, worldIn, pos);
}
}
@@ -222,15 +222,15 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
@Override
public int colorMultiplier(IBlockAccess world, BlockPos pos, int renderPass) {
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof ICamouflagedBlock){
if (tile instanceof ICamouflagedBlock) {
ItemStack camouflageStack = CamouflageUtil.getCamouflageBlock(world, pos);
if(renderPass < 100 && camouflageStack != null){
if (renderPass < 100 && camouflageStack != null) {
return Block.getBlockFromItem(camouflageStack.getItem()).colorMultiplier(world, pos, renderPass);
}
return super.colorMultiplier(world, pos, renderPass);
}else{
} else {
return super.colorMultiplier(world, pos, renderPass);
}
}
@@ -239,7 +239,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer() {
if(getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
if (getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
return EnumWorldBlockLayer.TRANSLUCENT;
}
return EnumWorldBlockLayer.CUTOUT;
@@ -257,48 +257,44 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
if(worldIn.getBlockState(pos.up()).getBlock() == this){
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
if (worldIn.getBlockState(pos.up()).getBlock() == this) {
return false;
}
if(!(worldIn.getTileEntity(pos.up()) instanceof IGreenhouseComponent)){
if (!(worldIn.getTileEntity(pos.up()) instanceof IGreenhouseComponent)) {
return false;
}
}
return super.canPlaceBlockAt(worldIn, pos);
}
@Override
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
if (getGreenhouseType() == BlockGreenhouseType.GLASS)
{
if (worldIn.getBlockState(pos.offset(side.getOpposite())) != iblockstate)
{
return true;
}
if (getGreenhouseType() == BlockGreenhouseType.GLASS) {
if (worldIn.getBlockState(pos.offset(side.getOpposite())) != iblockstate) {
return true;
}
if (block == this)
{
return false;
}
}else if(getGreenhouseType() == BlockGreenhouseType.DOOR){
return super.shouldSideBeRendered(worldIn, pos, side);
}
if (block == this) {
return false;
}
} else if (getGreenhouseType() == BlockGreenhouseType.DOOR) {
return super.shouldSideBeRendered(worldIn, pos, side);
}
return block == this ? false : super.shouldSideBeRendered(worldIn, pos, side);
}
return block != this && super.shouldSideBeRendered(worldIn, pos, side);
}
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.sprinkler", "inventory"));
}else{
} else {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory"));
}
}
@@ -44,295 +44,276 @@ import forestry.core.proxy.Proxies;
import forestry.core.utils.Translator;
import forestry.greenhouse.tiles.TileGreenhouseDoor;
public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapperRegister {
public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapperRegister {
//The door properties
private static final PropertyDirection FACING = BlockDoor.FACING;
private static final PropertyBool OPEN = BlockDoor.OPEN;
private static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = BlockDoor.HINGE;
private static final PropertyBool POWERED = BlockDoor.POWERED;
private static final PropertyEnum<BlockDoor.EnumDoorHalf> HALF = BlockDoor.HALF;
public BlockGreenhouseDoor() {
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, false).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, false).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
}
//The door properties
private static final PropertyDirection FACING = BlockDoor.FACING;
private static final PropertyBool OPEN = BlockDoor.OPEN;
private static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = BlockDoor.HINGE;
private static final PropertyBool POWERED = BlockDoor.POWERED;
private static final PropertyEnum<BlockDoor.EnumDoorHalf> HALF = BlockDoor.HALF;
@Override
public String getLocalizedName(){
return Translator.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
}
public BlockGreenhouseDoor() {
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, false).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, false).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
}
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
public String getLocalizedName() {
return Translator.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
}
@Override
public boolean isPassable(IBlockAccess worldIn, BlockPos pos){
return isOpen(combineMetadata(worldIn, pos));
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean isFullCube(){
return false;
}
@Override
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
return isOpen(combineMetadata(worldIn, pos));
}
@Override
@Override
public boolean isFullCube() {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos){
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getSelectedBoundingBox(worldIn, pos);
}
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) {
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getSelectedBoundingBox(worldIn, pos);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state){
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getCollisionBoundingBox(worldIn, pos, state);
}
@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getCollisionBoundingBox(worldIn, pos, state);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos){
this.setBoundBasedOnMeta(combineMetadata(worldIn, pos));
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
this.setBoundBasedOnMeta(combineMetadata(worldIn, pos));
}
private void setBoundBasedOnMeta(int combinedMeta){
float f = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
EnumFacing enumfacing = getFacing(combinedMeta);
boolean flag = isOpen(combinedMeta);
boolean flag1 = isHingeLeft(combinedMeta);
private void setBoundBasedOnMeta(int combinedMeta) {
float f = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
EnumFacing enumfacing = getFacing(combinedMeta);
boolean flag = isOpen(combinedMeta);
boolean flag1 = isHingeLeft(combinedMeta);
if (flag){
if (enumfacing == EnumFacing.EAST){
if (!flag1){
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}else{
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
}else if (enumfacing == EnumFacing.SOUTH){
if (!flag1){
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}else{
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}else if (enumfacing == EnumFacing.WEST){
if (!flag1){
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}else{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
}else if (enumfacing == EnumFacing.NORTH){
if (!flag1){
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}else{
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
}else if (enumfacing == EnumFacing.EAST){
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}else if (enumfacing == EnumFacing.SOUTH){
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}else if (enumfacing == EnumFacing.WEST){
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}else if (enumfacing == EnumFacing.NORTH){
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
}
if (flag) {
if (enumfacing == EnumFacing.EAST) {
if (!flag1) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
} else {
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
} else if (enumfacing == EnumFacing.SOUTH) {
if (!flag1) {
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} else {
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
} else if (enumfacing == EnumFacing.WEST) {
if (!flag1) {
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
} else {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
} else if (enumfacing == EnumFacing.NORTH) {
if (!flag1) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
} else {
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
} else if (enumfacing == EnumFacing.EAST) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
} else if (enumfacing == EnumFacing.SOUTH) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
} else if (enumfacing == EnumFacing.WEST) {
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} else if (enumfacing == EnumFacing.NORTH) {
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ){
TileEntity tile = world.getTileEntity(pos);
if(!(tile instanceof TileGreenhouseDoor)){
return false;
}
TileGreenhouseDoor door = (TileGreenhouseDoor) tile;
if(!door.getAccessHandler().allowsInteracting(player)){
return false;
}else{
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
IBlockState iblockstate = pos.equals(blockpos) ? state : world.getBlockState(blockpos);
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileGreenhouseDoor)) {
return false;
}
TileGreenhouseDoor door = (TileGreenhouseDoor) tile;
if (!door.getAccessHandler().allowsInteracting(player)) {
return false;
} else {
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
IBlockState iblockstate = pos.equals(blockpos) ? state : world.getBlockState(blockpos);
if (iblockstate.getBlock() != this)
{
return false;
}else{
state = iblockstate.cycleProperty(OPEN);
world.setBlockState(blockpos, state, 2);
world.markBlockRangeForRenderUpdate(blockpos, pos);
world.playAuxSFXAtEntity(player, state.getValue(OPEN) ? 1003 : 1006, pos, 0);
return true;
}
}
}
if (iblockstate.getBlock() != this) {
return false;
} else {
state = iblockstate.cycleProperty(OPEN);
world.setBlockState(blockpos, state, 2);
world.markBlockRangeForRenderUpdate(blockpos, pos);
world.playAuxSFXAtEntity(player, state.getValue(OPEN) ? 1003 : 1006, pos, 0);
return true;
}
}
}
public void toggleDoor(World worldIn, BlockPos pos, boolean open){
IBlockState iblockstate = worldIn.getBlockState(pos);
@Override
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
BlockPos blockpos = pos.down();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() == this){
BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() != this) {
worldIn.setBlockToAir(pos);
} else if (neighborBlock != this) {
this.onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
}
} else {
boolean flag1 = false;
BlockPos blockpos1 = pos.up();
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
if (iblockstate1.getBlock() == this && iblockstate1.getValue(OPEN) != open) {
worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, open), 2);
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
worldIn.playAuxSFXAtEntity((EntityPlayer)null, open ? 1003 : 1006, pos, 0);
}
}
}
@Override
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock){
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER){
BlockPos blockpos = pos.down();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate1.getBlock() != this) {
worldIn.setBlockToAir(pos);
flag1 = true;
}
if (iblockstate.getBlock() != this){
worldIn.setBlockToAir(pos);
}else if (neighborBlock != this){
this.onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
}
}else{
boolean flag1 = false;
BlockPos blockpos1 = pos.up();
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down())) {
worldIn.setBlockToAir(pos);
flag1 = true;
if (iblockstate1.getBlock() != this){
worldIn.setBlockToAir(pos);
flag1 = true;
}
if (iblockstate1.getBlock() == this) {
worldIn.setBlockToAir(blockpos1);
}
}
if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down())){
worldIn.setBlockToAir(pos);
flag1 = true;
if (flag1) {
if (!worldIn.isRemote) {
this.dropBlockAsItem(worldIn, pos, state, 0);
}
} else {
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
if (iblockstate1.getBlock() == this){
worldIn.setBlockToAir(blockpos1);
}
}
if ((flag || neighborBlock.canProvidePower()) && neighborBlock != this && flag != iblockstate1.getValue(POWERED)) {
worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, flag), 2);
if (flag1){
if (!worldIn.isRemote){
this.dropBlockAsItem(worldIn, pos, state, 0);
}
}else{
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
if (flag != state.getValue(OPEN)) {
worldIn.setBlockState(pos, state.withProperty(OPEN, flag), 2);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
worldIn.playAuxSFXAtEntity((EntityPlayer) null, flag ? 1003 : 1006, pos, 0);
}
}
}
}
}
if ((flag || neighborBlock.canProvidePower()) && neighborBlock != this && flag != iblockstate1.getValue(POWERED)) {
worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, flag), 2);
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : Item.getItemFromBlock(state.getBlock());
}
if (flag != state.getValue(OPEN)) {
worldIn.setBlockState(pos, state.withProperty(OPEN, flag), 2);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
worldIn.playAuxSFXAtEntity((EntityPlayer)null, flag ? 1003 : 1006, pos, 0);
}
}
}
}
}
@Override
public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end) {
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.collisionRayTrace(worldIn, pos, start, end);
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune){
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : Item.getItemFromBlock(state.getBlock());
}
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return pos.getY() < worldIn.getHeight() - 1 && (World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up()));
}
@Override
public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end){
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.collisionRayTrace(worldIn, pos, start, end);
}
@Override
public int getMobilityFlag() {
return 1;
}
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos){
return pos.getY() < worldIn.getHeight() - 1 && (World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up()));
}
private static int combineMetadata(IBlockAccess worldIn, BlockPos pos) {
IBlockState iblockstate = worldIn.getBlockState(pos);
int i = iblockstate.getBlock().getMetaFromState(iblockstate);
boolean flag = isTop(i);
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
int j = iblockstate1.getBlock().getMetaFromState(iblockstate1);
int k = flag ? j : i;
IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
int l = iblockstate2.getBlock().getMetaFromState(iblockstate2);
int i1 = flag ? i : l;
boolean flag1 = (i1 & 1) != 0;
boolean flag2 = (i1 & 2) != 0;
return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0);
}
@Override
public int getMobilityFlag(){
return 1;
}
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
BlockPos blockpos = pos.down();
private static int combineMetadata(IBlockAccess worldIn, BlockPos pos){
IBlockState iblockstate = worldIn.getBlockState(pos);
int i = iblockstate.getBlock().getMetaFromState(iblockstate);
boolean flag = isTop(i);
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
int j = iblockstate1.getBlock().getMetaFromState(iblockstate1);
int k = flag ? j : i;
IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
int l = iblockstate2.getBlock().getMetaFromState(iblockstate2);
int i1 = flag ? i : l;
boolean flag1 = (i1 & 1) != 0;
boolean flag2 = (i1 & 2) != 0;
return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0);
}
if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this) {
worldIn.setBlockToAir(blockpos);
}
}
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player){
BlockPos blockpos = pos.down();
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER) {
IBlockState iblockstate = worldIn.getBlockState(pos.up());
if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
{
worldIn.setBlockToAir(blockpos);
}
}
if (iblockstate.getBlock() == this) {
state = state.withProperty(HINGE, iblockstate.getValue(HINGE)).withProperty(POWERED, iblockstate.getValue(POWERED));
}
} else {
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER){
IBlockState iblockstate = worldIn.getBlockState(pos.up());
if (iblockstate1.getBlock() == this) {
state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN));
}
}
if (iblockstate.getBlock() == this){
state = state.withProperty(HINGE, iblockstate.getValue(HINGE)).withProperty(POWERED, iblockstate.getValue(POWERED));
}
}else{
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
return state;
}
if (iblockstate1.getBlock() == this){
state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN));
}
}
@Override
public IBlockState getStateFromMeta(int meta) {
return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, (meta & 2) > 0) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, (meta & 4) > 0);
}
return state;
}
@Override
public IBlockState getStateFromMeta(int meta){
return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf((meta & 2) > 0)) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
}
@Override
@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer(){
return EnumWorldBlockLayer.TRANSLUCENT;
}
public EnumWorldBlockLayer getBlockLayer() {
return EnumWorldBlockLayer.TRANSLUCENT;
}
@Override
public int getMetaFromState(IBlockState state){
int i = 0;
@Override
public int getMetaFromState(IBlockState state) {
int i = 0;
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER){
i = i | 8;
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
i = i | 8;
if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
{
i |= 1;
}
if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT) {
i |= 1;
}
if (state.getValue(POWERED))
{
i |= 2;
}
}else{
i = i | state.getValue(FACING).rotateY().getHorizontalIndex();
if (state.getValue(POWERED)) {
i |= 2;
}
} else {
i = i | state.getValue(FACING).rotateY().getHorizontalIndex();
if (state.getValue(OPEN)) {
i |= 4;
}
}
if (state.getValue(OPEN)) {
i |= 4;
}
}
return i;
}
return i;
}
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
@@ -342,59 +323,51 @@ public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMappe
@SideOnly(Side.CLIENT)
@Override
public void registerStateMapper() {
Proxies.render.registerStateMapper(this, new StateMap.Builder().ignore(BlockDoor.POWERED).build());
}
Proxies.render.registerStateMapper(this, new StateMap.Builder().ignore(BlockDoor.POWERED).build());
}
protected static int removeHalfBit(int meta)
{
return meta & 7;
}
protected static int removeHalfBit(int meta) {
return meta & 7;
}
public static boolean isOpen(IBlockAccess worldIn, BlockPos pos)
{
return isOpen(combineMetadata(worldIn, pos));
}
public static boolean isOpen(IBlockAccess worldIn, BlockPos pos) {
return isOpen(combineMetadata(worldIn, pos));
}
public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
{
return getFacing(combineMetadata(worldIn, pos));
}
public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos) {
return getFacing(combineMetadata(worldIn, pos));
}
public static EnumFacing getFacing(int combinedMeta)
{
return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
}
public static EnumFacing getFacing(int combinedMeta) {
return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
}
protected static boolean isOpen(int combinedMeta)
{
return (combinedMeta & 4) != 0;
}
protected static boolean isOpen(int combinedMeta) {
return (combinedMeta & 4) != 0;
}
protected static boolean isTop(int meta)
{
return (meta & 8) != 0;
}
protected static boolean isTop(int meta) {
return (meta & 8) != 0;
}
protected static boolean isHingeLeft(int combinedMeta)
{
return (combinedMeta & 16) != 0;
}
protected static boolean isHingeLeft(int combinedMeta) {
return (combinedMeta & 16) != 0;
}
@Override
protected BlockState createBlockState()
{
return new BlockState(this, HALF, FACING, OPEN, HINGE, POWERED);
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
return state;
}
@Override
protected BlockState createBlockState() {
return new BlockState(this, HALF, FACING, OPEN, HINGE, POWERED);
}
@Nonnull
@Override
public BlockGreenhouseType getGreenhouseType() {
return BlockGreenhouseType.DOOR;
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
return state;
}
@Nonnull
@Override
public BlockGreenhouseType getGreenhouseType() {
return BlockGreenhouseType.DOOR;
}
}
@@ -1,10 +1,9 @@
package forestry.greenhouse.blocks;
import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.Locale;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -12,9 +11,10 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.ITextureManager;
import forestry.core.render.TextureManager;
import forestry.greenhouse.blocks.BlockGreenhouse.State;
import forestry.greenhouse.tiles.TileGreenhouseHatch;
@@ -57,18 +57,18 @@ public enum BlockGreenhouseType {
@SideOnly(Side.CLIENT)
private static EnumMap<BlockGreenhouseSprites, TextureAtlasSprite> sprites;
private static enum BlockGreenhouseSprites{
private enum BlockGreenhouseSprites {
PLAIN, GLASS, GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), BUTTERFLY_HATCH("butterfly_hatch");
public static final BlockGreenhouseSprites[] VALUES = values();
private String spriteName;
private final String spriteName;
private BlockGreenhouseSprites(String spriteName) {
BlockGreenhouseSprites(String spriteName) {
this.spriteName = spriteName;
}
private BlockGreenhouseSprites() {
BlockGreenhouseSprites() {
this.spriteName = null;
}
}
@@ -76,12 +76,12 @@ public enum BlockGreenhouseType {
@SideOnly(Side.CLIENT)
public static void registerSprites() {
sprites = new EnumMap<>(BlockGreenhouseSprites.class);
for(BlockGreenhouseSprites sprite : BlockGreenhouseSprites.VALUES){
if(sprite == BlockGreenhouseSprites.PLAIN){
for (BlockGreenhouseSprites sprite : BlockGreenhouseSprites.VALUES) {
if (sprite == BlockGreenhouseSprites.PLAIN) {
sprites.put(sprite, TextureManager.getSprite("minecraft", "blocks/brick"));
}else if(sprite == BlockGreenhouseSprites.GLASS){
} else if (sprite == BlockGreenhouseSprites.GLASS) {
sprites.put(sprite, TextureManager.getSprite("minecraft", "blocks/glass_green"));
}else{
} else {
sprites.put(sprite, TextureManager.registerSprite("blocks/greenhouse/" + sprite.spriteName));
}
}
@@ -93,26 +93,26 @@ public enum BlockGreenhouseType {
@SideOnly(Side.CLIENT)
public static TextureAtlasSprite getSprite(BlockGreenhouseType type, EnumFacing facing, @Nullable IBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos) {
TileEntity tile = null;
if(world != null && pos != null){
if (world != null && pos != null) {
tile = world.getTileEntity(pos);
}
switch (type) {
case PLAIN:
return sprites.get(BlockGreenhouseSprites.PLAIN);
case GLASS:
return sprites.get(BlockGreenhouseSprites.GLASS);
case PLAIN:
return sprites.get(BlockGreenhouseSprites.PLAIN);
case GLASS:
return sprites.get(BlockGreenhouseSprites.GLASS);
case GEARBOX:
return sprites.get(BlockGreenhouseSprites.GEARS);
case VALVE:
return sprites.get(BlockGreenhouseSprites.VALVE);
case FAN:
if(state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
return sprites.get(BlockGreenhouseSprites.FAN_OFF);
} else {
return sprites.get(BlockGreenhouseSprites.FAN_ON);
}
case HEATER:
if(state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
return sprites.get(BlockGreenhouseSprites.HEATER_OFF);
} else {
return sprites.get(BlockGreenhouseSprites.HEATER_ON);
@@ -123,26 +123,26 @@ public enum BlockGreenhouseType {
return sprites.get(BlockGreenhouseSprites.CONTROL);
case HATCH_OUTPUT:
case HATCH_INPUT:
if(tile == null || facing == null || !(tile instanceof TileGreenhouseHatch)){
if (tile == null || facing == null || !(tile instanceof TileGreenhouseHatch)) {
return sprites.get(BlockGreenhouseSprites.HATCH_DEFAULT);
}
TileGreenhouseHatch hatch = (TileGreenhouseHatch) tile;
if(hatch.getOutwardsDir() == null){
if (hatch.getOutwardsDir() == null) {
return sprites.get(BlockGreenhouseSprites.HATCH_DEFAULT);
}
if(hatch.getOutwardsDir() == facing){
if (hatch.getOutwardsDir() == facing) {
return sprites.get(BlockGreenhouseSprites.HATCH_OUTPUT);
}else if(hatch.getOutwardsDir().getOpposite() == facing){
} else if (hatch.getOutwardsDir().getOpposite() == facing) {
return sprites.get(BlockGreenhouseSprites.HATCH_INPUT);
}
return null;
case BUTTERFLY_HATCH:
if(facing == EnumFacing.DOWN || facing == EnumFacing.UP){
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
return null;
}
return sprites.get(BlockGreenhouseSprites.BUTTERFLY_HATCH);
default:
return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
}
}
@@ -2,13 +2,14 @@ package forestry.greenhouse.blocks;
import java.util.Map;
import forestry.core.blocks.BlockRegistry;
import forestry.core.items.ItemBlockForestry;
import forestry.greenhouse.items.ItemBlockGreenhouseDoor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class BlockRegistryGreenhouse extends BlockRegistry{
import forestry.core.blocks.BlockRegistry;
import forestry.core.items.ItemBlockForestry;
import forestry.greenhouse.items.ItemBlockGreenhouseDoor;
public class BlockRegistryGreenhouse extends BlockRegistry {
private final Map<BlockGreenhouseType, BlockGreenhouse> greenhouseBlockMap;
@@ -16,7 +17,7 @@ public class BlockRegistryGreenhouse extends BlockRegistry{
greenhouseBlockMap = BlockGreenhouse.create();
for (BlockGreenhouse block : greenhouseBlockMap.values()) {
ItemBlock itemBlock = new ItemBlockForestry(block);
if(block instanceof BlockGreenhouseDoor){
if (block instanceof BlockGreenhouseDoor) {
itemBlock = new ItemBlockGreenhouseDoor(block);
}
registerBlock(block, itemBlock, "greenhouse." + block.getGreenhouseType());
@@ -11,7 +11,9 @@
package forestry.greenhouse.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fluids.IFluidTank;
import forestry.core.gui.ContainerTile;
import forestry.core.gui.slots.SlotFiltered;
import forestry.core.network.packets.PacketGuiUpdate;
@@ -11,7 +11,9 @@
package forestry.greenhouse.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fluids.IFluidTank;
import forestry.core.gui.ContainerTile;
import forestry.core.gui.slots.SlotOutput;
import forestry.core.network.packets.PacketGuiUpdate;
@@ -11,6 +11,7 @@
package forestry.greenhouse.gui;
import net.minecraft.entity.player.EntityPlayer;
import forestry.api.core.EnumCamouflageType;
import forestry.core.config.Constants;
import forestry.core.gui.GuiForestryTitled;
@@ -11,6 +11,7 @@
package forestry.greenhouse.gui;
import net.minecraft.entity.player.EntityPlayer;
import forestry.core.config.Constants;
import forestry.core.gui.GuiForestryTitled;
import forestry.core.gui.ledgers.ClimateLedger;
Loaded 100 of 132 files, more files were not shown because too many files have changed in this diff. Show more