mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c289590740 | ||
|
|
714858be99 | ||
|
|
5bb60cad8a | ||
|
|
b8cf4ef1cf | ||
|
|
d35075d681 | ||
|
|
79c56311c2 | ||
|
|
77cea8a645 | ||
|
|
ed00ca3158 | ||
|
|
418f00abf2 | ||
|
|
0fa8fdad39 | ||
|
|
0a110eb761 | ||
|
|
9feb5cb114 | ||
|
|
7aa44fb1fa | ||
|
|
84fa956ce4 | ||
|
|
0c14a85c31 | ||
|
|
a20fbbe60f | ||
|
|
27d932ee34 | ||
|
|
52b1784f25 | ||
|
|
154f4f2712 |
No files matched your search
+1
-7
@@ -108,13 +108,7 @@ allprojects {
|
||||
}
|
||||
|
||||
jar {
|
||||
// Copy redstone api into the jar, should shade this as a maven dep...
|
||||
from (sourceSets.api.allSource) {
|
||||
include 'cofh/**/*.txt'
|
||||
}
|
||||
from (sourceSets.api.output.classesDir) {
|
||||
include 'cofh/**/*.*'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
mcversion=1.10.2
|
||||
forgeversion=12.18.1.2060
|
||||
forgeversion=12.18.1.2080
|
||||
mcp_mappings=snapshot_20160525
|
||||
|
||||
tesla_version=1.10.2-1.2.1.42
|
||||
@@ -8,4 +8,4 @@ ic2_version=2.6.38-ex110
|
||||
|
||||
version_major=5
|
||||
version_minor=2
|
||||
version_patch=9
|
||||
version_patch=11
|
||||
+1
-1
Submodule lang updated: 4c93562cb9...a31d99f6f6.
@@ -52,7 +52,7 @@ import forestry.plugins.PluginManager;
|
||||
version = Constants.VERSION,
|
||||
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
|
||||
acceptedMinecraftVersions = "[1.10]",
|
||||
dependencies = "required-after:Forge@[12.18.0.1989,);"
|
||||
dependencies = "required-after:Forge@[12.18.1.2080,);"
|
||||
+ "after:JEI@[3.8.0,);"
|
||||
+ "after:" + PluginIC2.modId + ";")
|
||||
public class Forestry {
|
||||
|
||||
@@ -7,11 +7,11 @@ package forestry.api.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.genetics.IHousing;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package forestry.api.climate;
|
||||
|
||||
public enum EnumClimatiserModes {
|
||||
|
||||
POSITIVE, NEGATIVE, NONE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package forestry.api.climate;
|
||||
|
||||
public enum EnumClimatiserTypes {
|
||||
|
||||
TEMPERATURE, HUMIDITY, NONE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimateControl {
|
||||
|
||||
float getControlTemperature();
|
||||
|
||||
float getControlHumidity();
|
||||
|
||||
void setControlTemperature(float temperature);
|
||||
|
||||
void setControlHumidity(float humidity);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
public interface IClimateControlProvider extends ILocatable {
|
||||
|
||||
IClimateControl getClimateControl();
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimateControlled {
|
||||
/**
|
||||
+3
-7
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -11,7 +11,6 @@ import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -27,9 +26,9 @@ public interface IClimateManager {
|
||||
|
||||
void removeRegion(IClimateRegion region);
|
||||
|
||||
void addSource(IClimateSource source);
|
||||
void addSource(IClimateSourceProvider source);
|
||||
|
||||
void removeSource(IClimateSource source);
|
||||
void removeSource(IClimateSourceProvider source);
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegionForPos(World world, BlockPos pos);
|
||||
@@ -37,7 +36,4 @@ public interface IClimateManager {
|
||||
@Nonnull
|
||||
Map<Integer, List<IClimateRegion>> getRegions();
|
||||
|
||||
@Nonnull
|
||||
Map<Integer, Map<BlockPos, IClimateSource>> getSources();
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public interface IClimateProvider {
|
||||
Biome getBiome();
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
}
|
||||
+16
-6
@@ -3,9 +3,9 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -21,15 +21,25 @@ public interface IClimateRegion extends INbtReadable, INbtWritable {
|
||||
World getWorld();
|
||||
|
||||
/**
|
||||
* Update the climate in a region, all 20 world ticks.
|
||||
* Update the climate in a region.
|
||||
*/
|
||||
void updateClimate();
|
||||
void updateClimate(int ticks);
|
||||
|
||||
int getTicksPerUpdate();
|
||||
|
||||
@Nonnull
|
||||
Map<BlockPos, IClimatePosition> getPositions();
|
||||
|
||||
int getTicksPerUpdate();
|
||||
void addSource(IClimateSource source);
|
||||
|
||||
List<BlockPos> getOtherPositions();
|
||||
void removeSource(IClimateSource source);
|
||||
|
||||
Collection<IClimateSource> getSources();
|
||||
|
||||
Collection<BlockPos> getOtherPositions();
|
||||
|
||||
float getTemperature();
|
||||
|
||||
float getHumidity();
|
||||
|
||||
}
|
||||
+4
-9
@@ -3,29 +3,24 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
package forestry.api.climate;
|
||||
|
||||
/**
|
||||
* A climate source is used to change the climate in a region.
|
||||
*/
|
||||
public interface IClimateSource {
|
||||
|
||||
|
||||
/**
|
||||
* @param tickCount The current tick count.
|
||||
* @param region The climate region, in that the source stands.
|
||||
*/
|
||||
void changeClimate(int tickCount, IClimateRegion region);
|
||||
|
||||
|
||||
/**
|
||||
* @return The ticks that are required for one change.
|
||||
*/
|
||||
int getTicksForChange(IClimateRegion region);
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getPos();
|
||||
IClimateSourceProvider getProvider();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
public interface IClimateSourceProvider extends ILocatable {
|
||||
|
||||
IClimateSource getClimateSource();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
public interface IClimatiserDefinition {
|
||||
|
||||
float getChange();
|
||||
|
||||
double getRange();
|
||||
|
||||
EnumClimatiserModes getMode();
|
||||
|
||||
EnumClimatiserTypes getType();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@API(apiVersion = "2.1.0", owner = "Forestry", provides = "ForestryAPI|climate")
|
||||
package forestry.api.climate;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -7,7 +7,7 @@ package forestry.api.core;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.climate.IClimateManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ public interface ICamouflageAccess {
|
||||
|
||||
boolean isItemBlackListed(@Nonnull String type, @Nonnull ItemStack camouflageBlock);
|
||||
|
||||
ICamouflageItemHandler getHandlerFromItem(ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -6,21 +6,19 @@
|
||||
package forestry.api.core;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ICamouflageHandler{
|
||||
public interface ICamouflageHandler extends ILocatable {
|
||||
|
||||
/**
|
||||
* @return The item of the block that is the camouflage of this handler for the type.
|
||||
*/
|
||||
ItemStack getCamouflageBlock(String type);
|
||||
|
||||
|
||||
/**
|
||||
* @return The default camouflage block item for the type.
|
||||
*/
|
||||
ItemStack getDefaultCamouflageBlock(String type);
|
||||
|
||||
|
||||
/**
|
||||
* @return True if the handler can handle this type of camouflage.
|
||||
*/
|
||||
@@ -30,11 +28,4 @@ public interface ICamouflageHandler{
|
||||
* Set the camouflage block item for the type.
|
||||
*/
|
||||
void setCamouflageBlock(String type, ItemStack camouflageBlock);
|
||||
|
||||
/**
|
||||
* @return The coordinates of the handler as a BlockPos.
|
||||
*/
|
||||
BlockPos getCoordinates();
|
||||
|
||||
World getWorld();
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public interface ICamouflageItemHandler {
|
||||
|
||||
boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler);
|
||||
boolean canHandle(ItemStack stack);
|
||||
|
||||
String getType();
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package forestry.api.core;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public interface IClimateProvider {
|
||||
Biome getBiome();
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
}
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
/*******************************************************************************
|
||||
* 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.tiles;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ILocatable {
|
||||
BlockPos getCoordinates();
|
||||
|
||||
/** Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 */
|
||||
World getWorldObj();
|
||||
}
|
||||
/*******************************************************************************
|
||||
* 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.api.core;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ILocatable {
|
||||
BlockPos getCoordinates();
|
||||
|
||||
/** Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 */
|
||||
World getWorldObj();
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@API(apiVersion = "5.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|greenhouse")
|
||||
@API(apiVersion = "5.2.0", owner = "ForestryAPI|core", provides = "ForestryAPI|greenhouse")
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -5,7 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IHousing;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ package forestry.api.multiblock;
|
||||
|
||||
import forestry.api.apiculture.IBeeListener;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
|
||||
/**
|
||||
* Needs to be implemented by TileEntities that want to be part of an alveary.
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.multiblock;
|
||||
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.greenhouse.IGreenhouseListener;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -18,10 +21,17 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
|
||||
IGreenhouseListener getGreenhouseListener();
|
||||
}
|
||||
|
||||
interface ClimateControl extends IGreenhouseComponent, IClimateControlProvider {
|
||||
|
||||
@Override
|
||||
IClimateControl getClimateControl();
|
||||
}
|
||||
|
||||
interface Door extends IGreenhouseComponent {
|
||||
}
|
||||
|
||||
interface Climatiser extends IGreenhouseComponent, IClimateSource {
|
||||
interface Climatiser extends IGreenhouseComponent, IClimateSourceProvider {
|
||||
IClimatiserDefinition getDefinition();
|
||||
}
|
||||
|
||||
interface ButterflyHatch extends IGreenhouseComponent {
|
||||
|
||||
@@ -7,15 +7,18 @@ package forestry.api.multiblock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler {
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
|
||||
|
||||
/**
|
||||
* Handle change events.
|
||||
@@ -29,5 +32,9 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegion();
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
IClimateControl getClimateControl();
|
||||
|
||||
}
|
||||
@@ -556,7 +556,7 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{items.honeydew.getItemStack()}, honeyDropFluid);
|
||||
|
||||
ItemStack phosphor = PluginCore.items.phosphor.getItemStack(2);
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{phosphor, new ItemStack(Blocks.SAND)}, new FluidStack(FluidRegistry.WATER, 2000));
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{phosphor, new ItemStack(Blocks.SAND)}, new FluidStack(FluidRegistry.LAVA, 2000));
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{phosphor, new ItemStack(Blocks.SAND, 1, 1)}, new FluidStack(FluidRegistry.LAVA, 2000));
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{phosphor, new ItemStack(Blocks.DIRT)}, new FluidStack(FluidRegistry.LAVA, 1600));
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import forestry.api.apiculture.IBeeHousingInventory;
|
||||
import forestry.api.apiculture.IBeeListener;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.core.BiomeHelper;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.apiculture.AlvearyBeeModifier;
|
||||
|
||||
@@ -13,19 +13,20 @@ package forestry.apiculture.multiblock;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.energy.EnergyTransferMode;
|
||||
import forestry.energy.compat.rf.IEnergyReceiverDelegated;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiver, IActivatable, IAlvearyComponent.Climatiser {
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiverDelegated, IActivatable, IAlvearyComponent.Climatiser {
|
||||
|
||||
private static final int WORK_CYCLES = 1;
|
||||
private static final int ENERGY_PER_OPERATION = 50;
|
||||
@@ -50,13 +51,13 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
this.definition = definition;
|
||||
|
||||
this.energyManager = new EnergyManager(1000, 2000);
|
||||
this.energyManager.setReceiveOnly();
|
||||
this.energyManager.setExternalMode(EnergyTransferMode.RECEIVE);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void changeClimate(int tick, IClimateControlled climateControlled) {
|
||||
if (workingTime < 20 && energyManager.consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) {
|
||||
if (workingTime < 20 && EnergyHelper.consumeEnergyToDoWork(energyManager, WORK_CYCLES, ENERGY_PER_OPERATION)) {
|
||||
// one tick of work for every 10 RF
|
||||
workingTime += ENERGY_PER_OPERATION / 10;
|
||||
}
|
||||
@@ -123,25 +124,9 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
return energyManager.receiveEnergy(from, maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return energyManager.getEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return energyManager.getMaxEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return energyManager.canConnectEnergy(from);
|
||||
public EnergyManager getEnergyManager() {
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import forestry.api.core.climate.IClimateControlled;
|
||||
import forestry.api.climate.IClimateControlled;
|
||||
import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.apiculture.blocks.BlockAlvearyType;
|
||||
import forestry.apiculture.gui.ContainerAlvearyHygroregulator;
|
||||
|
||||
@@ -47,6 +47,8 @@ import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntityEnderman;
|
||||
import net.minecraft.entity.monster.EntityPigZombie;
|
||||
import net.minecraft.entity.monster.IMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -55,6 +57,7 @@ import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntitySelectors;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -65,20 +68,6 @@ import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class TileHive extends TileEntity implements ITickable, IHiveTile, IActivatable, IBeeHousing {
|
||||
private static final DamageSource damageSourceBeeHive = new DamageSourceForestry("bee.hive");
|
||||
private static final Predicate<EntityLivingBase> BEE_TARGET_PREDICATE = new Predicate<EntityLivingBase>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable EntityLivingBase input) {
|
||||
if (input != null && input.isEntityAlive() && !input.isInvisible()) {
|
||||
if (input instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer) input;
|
||||
return !player.isSpectator() && !player.isCreative();
|
||||
} else if (input instanceof IMob) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@Nonnull
|
||||
private final InventoryAdapter contained = new InventoryAdapter(2, "Contained");
|
||||
@@ -88,6 +77,9 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
private final BeekeepingLogic beeLogic;
|
||||
@Nonnull
|
||||
private final IErrorLogic errorLogic;
|
||||
@Nonnull
|
||||
private final Predicate<EntityLivingBase> beeTargetPredicate;
|
||||
|
||||
private IBee containedBee = null;
|
||||
private boolean active = false;
|
||||
private boolean angry = false;
|
||||
@@ -103,6 +95,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
inventory = new HiveBeeHousingInventory(this);
|
||||
beeLogic = new BeekeepingLogic(this);
|
||||
errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
|
||||
beeTargetPredicate = new BeeTargetPredicate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,7 +120,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
if (calmTime == 0) {
|
||||
if (canWork) {
|
||||
AxisAlignedBB boundingBox = AlleleEffect.getBounding(getContainedBee().getGenome(), this);
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox, BEE_TARGET_PREDICATE);
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox, beeTargetPredicate);
|
||||
if (!entities.isEmpty()) {
|
||||
Collections.shuffle(entities);
|
||||
EntityLivingBase entity = entities.get(0);
|
||||
@@ -371,4 +364,28 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
return getPos();
|
||||
}
|
||||
|
||||
private static class BeeTargetPredicate implements Predicate<EntityLivingBase> {
|
||||
@Nonnull
|
||||
private final IHiveTile hive;
|
||||
|
||||
public BeeTargetPredicate(@Nonnull IHiveTile hive) {
|
||||
this.hive = hive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable EntityLivingBase input) {
|
||||
if (input != null && input.isEntityAlive() && !input.isInvisible()) {
|
||||
if (input instanceof EntityPlayer) {
|
||||
return EntitySelectors.CAN_AI_TARGET.apply(input);
|
||||
} else if (hive.isAngry()) {
|
||||
return true;
|
||||
} else if (input instanceof IMob) {
|
||||
// don't attack semi-passive vanilla mobs
|
||||
return !(input instanceof EntityEnderman) && !(input instanceof EntityPigZombie);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public enum HiveDescription implements IHiveDescription {
|
||||
}
|
||||
},
|
||||
JUNGLE(IHiveRegistry.HiveType.JUNGLE, 6.0f, BeeDefinition.TROPICAL, HiveManager.genHelper.tree()),
|
||||
END(IHiveRegistry.HiveType.END, 6.0f, BeeDefinition.ENDED, HiveManager.genHelper.ground(Blocks.END_STONE, Blocks.END_BRICKS)) {
|
||||
END(IHiveRegistry.HiveType.END, 2.0f, BeeDefinition.ENDED, HiveManager.genHelper.ground(Blocks.END_STONE, Blocks.END_BRICKS)) {
|
||||
@Override
|
||||
public boolean isGoodBiome(Biome biome) {
|
||||
return BiomeDictionary.isBiomeOfType(biome, BiomeDictionary.Type.END);
|
||||
|
||||
@@ -15,6 +15,8 @@ import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.arboriculture.items.ItemBlockWoodDoor;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -23,15 +25,15 @@ import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class CamouflageHandlerArbDoor implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
return false;
|
||||
}
|
||||
if(stack.getItem() instanceof ItemBlockWoodDoor){
|
||||
@@ -56,22 +58,22 @@ public class CamouflageHandlerArbDoor implements ICamouflageItemHandler {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || !(stack.getItem() instanceof ItemBlockWoodDoor)){
|
||||
return null;
|
||||
}
|
||||
World world = camouflageHandler.getWorld();
|
||||
World world = camouflageHandler.getWorldObj();
|
||||
BlockPos pos = camouflageTile.getCoordinates();
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
IBlockState currentState = blockState.getActualState(world, pos);
|
||||
|
||||
|
||||
ItemBlockWoodDoor itemDoor = (ItemBlockWoodDoor) stack.getItem();
|
||||
|
||||
|
||||
IBlockState doorState = itemDoor.block.getDefaultState()
|
||||
.withProperty(BlockDoor.FACING, currentState.getValue(BlockDoor.FACING))
|
||||
.withProperty(BlockDoor.HINGE, currentState.getValue(BlockDoor.HINGE))
|
||||
.withProperty(BlockDoor.OPEN, currentState.getValue(BlockDoor.OPEN))
|
||||
.withProperty(BlockDoor.POWERED, currentState.getValue(BlockDoor.POWERED))
|
||||
.withProperty(BlockDoor.HALF, currentState.getValue(BlockDoor.HALF));
|
||||
|
||||
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
|
||||
|
||||
return Pair.of(doorState, modelShapes.getModelForState(doorState));
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
}
|
||||
|
||||
//Dirt Pile Block
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.DIRT)), OreDictUtil.DUST_ASH, Items.CLAY_BALL, OreDictUtil.DUST_ASH, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.TREE_LEAVES, Items.CLAY_BALL, OreDictUtil.TREE_LEAVES);
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.DIRT)), PluginCore.items.fertilizerBio, Items.CLAY_BALL, PluginCore.items.fertilizerBio, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.DIRT, PluginCore.items.fertilizerBio, Items.CLAY_BALL, PluginCore.items.fertilizerBio);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.google.gson.stream.JsonReader;
|
||||
|
||||
import forestry.api.arboriculture.IWoodType;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.core.render.FontColour;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -20,7 +20,6 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import forestry.api.core.ICamouflageAccess;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
@@ -48,6 +47,13 @@ public class CamouflageAccess implements ICamouflageAccess {
|
||||
|
||||
@Override
|
||||
public List<ICamouflageItemHandler> getCamouflageItemHandler(String type) {
|
||||
if(type == null){
|
||||
List<ICamouflageItemHandler> handlers = new ArrayList<>();
|
||||
for(List<ICamouflageItemHandler> handler : camouflageItemHandlers.values()){
|
||||
handlers.addAll(handler);
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
if(!camouflageItemHandlers.containsKey(type)){
|
||||
return null;
|
||||
}
|
||||
@@ -76,21 +82,31 @@ public class CamouflageAccess implements ICamouflageAccess {
|
||||
|
||||
@Override
|
||||
public boolean isItemBlackListed(String type, ItemStack camouflageBlock) {
|
||||
if (camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null || !camouflageItemBlacklist.containsKey(type)) {
|
||||
if (camouflageBlock == null || camouflageBlock.getItem() == null || Block.getBlockFromItem(camouflageBlock.getItem()) == null || type != null && !camouflageItemBlacklist.containsKey(type)) {
|
||||
return false;
|
||||
}
|
||||
for (ItemStack camouflageBlacklisted : camouflageItemBlacklist.get(type)) {
|
||||
List<ItemStack> camouflageItemBlacklisted;
|
||||
if(type == null){
|
||||
camouflageItemBlacklisted = new ArrayList<>();
|
||||
for(List<ItemStack> stacks : camouflageItemBlacklist.values()){
|
||||
camouflageItemBlacklisted.addAll(stacks);
|
||||
}
|
||||
}else{
|
||||
camouflageItemBlacklisted = camouflageItemBlacklist.get(type);
|
||||
}
|
||||
for (ItemStack camouflageBlacklisted : camouflageItemBlacklisted) {
|
||||
if (camouflageBlacklisted.getItem() == camouflageBlock.getItem() && camouflageBlacklisted.getItemDamage() == camouflageBlock.getItemDamage() && ItemStack.areItemStackTagsEqual(camouflageBlock, camouflageBlacklisted)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ICamouflageItemHandler getHandlerFromItem(@Nonnull ItemStack camouflageItem, ICamouflageHandler camouflageHandler){
|
||||
|
||||
@Override
|
||||
public ICamouflageItemHandler getHandlerFromItem(ItemStack stack) {
|
||||
for(List<ICamouflageItemHandler> handlers : camouflageItemHandlers.values()){
|
||||
for(ICamouflageItemHandler handler : handlers){
|
||||
if(handler.canHandle(camouflageItem, camouflageHandler)){
|
||||
if(handler.canHandle(stack)){
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,32 +10,33 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelShapes;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class CamouflageHandlerDefault implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
return false;
|
||||
}
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
IBlockState stateFromMeta = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
return stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && block.isNormalCube(stateFromMeta, camouflageHandler.getWorld(), camouflageHandler.getCoordinates());
|
||||
return stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && block.isNormalCube(stateFromMeta) && block.isFullCube(stateFromMeta) && block.isBlockNormalCube(stateFromMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +58,7 @@ public class CamouflageHandlerDefault implements ICamouflageItemHandler {
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
|
||||
return Pair.of(state, modelShapes.getModelForState(state));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -33,8 +34,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class CamouflageHandlerDoor implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0){
|
||||
return false;
|
||||
}
|
||||
if(stack.getItem() instanceof ItemDoor){
|
||||
@@ -59,23 +60,23 @@ public class CamouflageHandlerDoor implements ICamouflageItemHandler {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || !(stack.getItem() instanceof ItemDoor)){
|
||||
return null;
|
||||
}
|
||||
World world = camouflageHandler.getWorld();
|
||||
World world = camouflageHandler.getWorldObj();
|
||||
BlockPos pos = camouflageTile.getCoordinates();
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
IBlockState currentState = blockState.getActualState(world, pos);
|
||||
|
||||
|
||||
ItemDoor itemDoor = (ItemDoor) stack.getItem();
|
||||
Block doorBlock = ObfuscationReflectionHelper.getPrivateValue(ItemDoor.class, itemDoor, 0);
|
||||
|
||||
|
||||
IBlockState doorState = doorBlock.getDefaultState()
|
||||
.withProperty(BlockDoor.FACING, currentState.getValue(BlockDoor.FACING))
|
||||
.withProperty(BlockDoor.HINGE, currentState.getValue(BlockDoor.HINGE))
|
||||
.withProperty(BlockDoor.OPEN, currentState.getValue(BlockDoor.OPEN))
|
||||
.withProperty(BlockDoor.POWERED, currentState.getValue(BlockDoor.POWERED))
|
||||
.withProperty(BlockDoor.HALF, currentState.getValue(BlockDoor.HALF));
|
||||
|
||||
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
|
||||
|
||||
return Pair.of(doorState, modelShapes.getModelForState(doorState));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class CamouflageHandlerGlass implements ICamouflageItemHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ItemStack stack, ICamouflageHandler camouflageHandler) {
|
||||
if(camouflageHandler == null || stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
public boolean canHandle(ItemStack stack) {
|
||||
if(stack == null || stack.getItem() == null || stack.stackSize <= 0 || Block.getBlockFromItem(stack.getItem()) == null){
|
||||
return false;
|
||||
}
|
||||
Block block = Block.getBlockFromItem(stack.getItem());
|
||||
IBlockState stateFromMeta = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
return !stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta);
|
||||
return !stateFromMeta.isOpaqueCube() && !block.hasTileEntity(stateFromMeta) && !block.isBlockNormalCube(stateFromMeta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.owner.GameProfileDataSerializer;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -54,12 +55,15 @@ import forestry.core.commands.CommandPlugins;
|
||||
import forestry.core.commands.RootCommand;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.genetics.alleles.AlleleFactory;
|
||||
import forestry.core.genetics.alleles.AlleleHelper;
|
||||
import forestry.core.genetics.alleles.AlleleRegistry;
|
||||
import forestry.core.items.EnumContainerType;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.loot.functions.SetSpeciesNBT;
|
||||
import forestry.core.models.ModelCamouflageSprayCan;
|
||||
import forestry.core.models.ModelEntry;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.multiblock.MultiblockLogicFactory;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
@@ -275,14 +279,28 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
// / WRENCH
|
||||
RecipeUtil.addRecipe(items.wrench, "# #", " # ", " # ", '#', OreDictUtil.INGOT_BRONZE);
|
||||
|
||||
// / CAMOUFLAGE SPRAY CAN
|
||||
RecipeUtil.addRecipe(items.camouflageSprayCan, "TTT", "TCT", "TCT", 'T', OreDictUtil.INGOT_TIN, 'C', items.craftingMaterial.getCamouflagedPaneling());
|
||||
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
|
||||
// / CARPENTER
|
||||
// Portable ANALYZER
|
||||
RecipeManagers.carpenterManager.addRecipe(100, new FluidStack(FluidRegistry.WATER, 2000), null, PluginCore.items.portableAlyzer.getItemStack(),
|
||||
"X#X", "X#X", "RDR",
|
||||
'#', OreDictUtil.PANE_GLASS,
|
||||
'X', OreDictUtil.INGOT_TIN,
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'D', OreDictUtil.GEM_DIAMOND);
|
||||
// Camouflaged Paneling
|
||||
RecipeManagers.carpenterManager.addRecipe(50, Fluids.BIOMASS.getFluid(500), null, PluginCore.items.craftingMaterial.getCamouflagedPaneling(4),
|
||||
"YAR", "B#B", "RPY",
|
||||
'#', OreDictUtil.PLANK_WOOD,
|
||||
'A', OreDictUtil.DUST_ASH,
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'P', OreDictUtil.PULP_WOOD,
|
||||
'R', OreDictUtil.DYE_RED,
|
||||
'B', OreDictUtil.DYE_BLUE,
|
||||
'Y', OreDictUtil.DYE_YELLOW);
|
||||
}else{
|
||||
// Portable ANALYZER
|
||||
RecipeUtil.addRecipe(PluginCore.items.portableAlyzer.getItemStack(),
|
||||
@@ -293,6 +311,16 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
'X', OreDictUtil.INGOT_TIN,
|
||||
'R', OreDictUtil.DUST_REDSTONE,
|
||||
'D', OreDictUtil.GEM_DIAMOND);
|
||||
// Camouflaged Paneling
|
||||
RecipeUtil.addRecipe(PluginCore.items.craftingMaterial.getCamouflagedPaneling(4),
|
||||
"WWW",
|
||||
"YBR",
|
||||
"WWW",
|
||||
'W', OreDictUtil.PLANK_WOOD,
|
||||
'D', OreDictUtil.DUST_REDSTONE,
|
||||
'Y', OreDictUtil.DYE_YELLOW,
|
||||
'B', OreDictUtil.DYE_BLUE,
|
||||
'R', OreDictUtil.DYE_RED);
|
||||
}
|
||||
|
||||
// ANALYZER
|
||||
@@ -449,6 +477,9 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onBakeModel(ModelBakeEvent event) {
|
||||
ModelResourceLocation modelLocation = new ModelResourceLocation("forestry:camouflageSprayCan", "inventory");
|
||||
ModelEntry blockModelIndex = new ModelEntry(modelLocation, new ModelCamouflageSprayCan());
|
||||
Proxies.render.registerModel(blockModelIndex);
|
||||
ModelManager.getInstance().registerCustomModels(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister {
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister, IBlockRotatable {
|
||||
/** use this instead of {@link BlockHorizontal#FACING} so the blocks rotate in a circle instead of NSWE order. */
|
||||
public static final PropertyEnum<EnumFacing> FACING = PropertyEnum.create("facing", EnumFacing.class, EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.DOWN, EnumFacing.UP);
|
||||
|
||||
@@ -170,6 +170,7 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class BlockStructure extends BlockForestry {
|
||||
return false;
|
||||
}
|
||||
|
||||
private long previousMessageTick = 0;
|
||||
protected long previousMessageTick = 0;
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package forestry.core.blocks;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBlockRotatable {
|
||||
|
||||
void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.greenhouse.multiblock.DefaultClimateControl;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class BiomeClimateControl extends DefaultClimateControl {
|
||||
|
||||
private static final Map<Biome, BiomeClimateControl> climateControls = new HashMap<>();
|
||||
|
||||
public static BiomeClimateControl getControl(Biome biome){
|
||||
if(!climateControls.containsKey(biome)){
|
||||
climateControls.put(biome, new BiomeClimateControl(biome));
|
||||
}
|
||||
return climateControls.get(biome);
|
||||
}
|
||||
|
||||
private final Biome biome;
|
||||
|
||||
private BiomeClimateControl(Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlTemperature() {
|
||||
return biome.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlHumidity() {
|
||||
return biome.getRainfall();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
|
||||
public class ClimateControl implements IClimateControl, INbtWritable, INbtReadable, IStreamable {
|
||||
|
||||
private float temperature;
|
||||
private float humidity;
|
||||
|
||||
public ClimateControl() {
|
||||
temperature = 2.0F;
|
||||
humidity = 2.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getControlHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlTemperature(float temperature) {
|
||||
if(temperature > 2.0F){
|
||||
temperature = 2.0F;
|
||||
}else{
|
||||
this.temperature = temperature;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlHumidity(float humidity) {
|
||||
if(humidity > 2.0F){
|
||||
humidity = 2.0F;
|
||||
}else{
|
||||
this.humidity = humidity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
temperature = nbt.getFloat("Temperature");
|
||||
humidity = nbt.getFloat("Humidity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("Temperature", temperature);
|
||||
nbt.setFloat("Humidity", humidity);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
public class ClimateEventHandler {
|
||||
|
||||
Map<Integer, Integer> serverTicks;
|
||||
|
||||
|
||||
public ClimateEventHandler() {
|
||||
serverTicks = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldTick(TickEvent.WorldTickEvent event) {
|
||||
Integer dim = Integer.valueOf(event.world.provider.getDimension());
|
||||
@@ -33,24 +39,11 @@ public class ClimateEventHandler {
|
||||
Map<Integer, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if(regions != null && regions.containsKey(dim)){
|
||||
for(IClimateRegion region : regions.get(dim)){
|
||||
if(ticks % region.getTicksPerUpdate() == 0){
|
||||
region.updateClimate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<Integer, Map<BlockPos, IClimateSource>> sources = ForestryAPI.climateManager.getSources();
|
||||
if(sources != null && sources.containsKey(dim)){
|
||||
for(IClimateSource source : sources.get(dim).values()){
|
||||
IClimateRegion region = ForestryAPI.climateManager.getRegionForPos(event.world, source.getPos());
|
||||
if(region != null){
|
||||
if(ticks % source.getTicksForChange(region) == 0){
|
||||
source.changeClimate(ticks, region);
|
||||
}
|
||||
}
|
||||
region.updateClimate(ticks);
|
||||
}
|
||||
}
|
||||
serverTicks.put(dim, ticks+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,35 +10,32 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.climate;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateManager;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
import forestry.core.DefaultClimateProvider;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimateManager implements IClimateManager{
|
||||
|
||||
protected Map<Integer, List<IClimateRegion>> regions;
|
||||
protected Map<Integer, Map<BlockPos, IClimateSource>> sources;
|
||||
|
||||
private final Object regionsMutex;
|
||||
|
||||
|
||||
public ClimateManager() {
|
||||
regions = new HashMap<>();
|
||||
sources = new HashMap<>();
|
||||
regionsMutex = new Object();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addRegion(IClimateRegion region) {
|
||||
if(region == null){
|
||||
@@ -60,7 +57,7 @@ public class ClimateManager implements IClimateManager{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeRegion(IClimateRegion region) {
|
||||
if(region == null){
|
||||
@@ -77,36 +74,52 @@ public class ClimateManager implements IClimateManager{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSource source) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!sources.containsKey(dimensionID)){
|
||||
sources.put(dimensionID, new HashMap<>());
|
||||
public void removeSource(IClimateSourceProvider source) {
|
||||
if(source == null){
|
||||
return;
|
||||
}
|
||||
if(sources.get(dimensionID).keySet().contains(source.getPos())){
|
||||
sources.get(dimensionID).remove(source.getPos(), source);
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorldObj().provider.getDimension());
|
||||
if(!regions.containsKey(dimensionID)){
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates());
|
||||
if(region != null){
|
||||
if(!region.getSources().contains(source.getClimateSource())){
|
||||
region.removeSource(source.getClimateSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addSource(IClimateSource source) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorld().provider.getDimension());
|
||||
if(!sources.containsKey(dimensionID)){
|
||||
sources.put(dimensionID, new HashMap<>());
|
||||
public void addSource(IClimateSourceProvider source) {
|
||||
if(source == null){
|
||||
return;
|
||||
}
|
||||
if(sources.get(dimensionID).get(source.getPos()) == null){
|
||||
sources.get(dimensionID).put(source.getPos(), source);
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = Integer.valueOf(source.getWorldObj().provider.getDimension());
|
||||
if(!regions.containsKey(dimensionID)){
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates());
|
||||
if(region != null){
|
||||
if(!region.getSources().contains(source.getClimateSource())){
|
||||
region.addSource(source.getClimateSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getTemperature(World world, BlockPos pos) {
|
||||
Biome biome = world.getBiome(pos);
|
||||
IClimateRegion region = getRegionForPos(world, pos);
|
||||
if(region!= null){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
|
||||
|
||||
if(position != null){
|
||||
return position.getTemperature();
|
||||
}
|
||||
@@ -120,19 +133,19 @@ public class ClimateManager implements IClimateManager{
|
||||
IClimateRegion region = getRegionForPos(world, pos);
|
||||
if(region!= null){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
|
||||
|
||||
if(position != null){
|
||||
return position.getHumidity();
|
||||
}
|
||||
}
|
||||
return biome.getRainfall();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<IClimateRegion>> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IClimateRegion getRegionForPos(World world, BlockPos pos){
|
||||
Integer dimensionID = Integer.valueOf(world.provider.getDimension());
|
||||
@@ -149,12 +162,7 @@ public class ClimateManager implements IClimateManager{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<BlockPos, IClimateSource>> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IClimateProvider getDefaultClimate(World world, BlockPos pos) {
|
||||
return new DefaultClimateProvider(world, pos);
|
||||
|
||||
@@ -12,8 +12,8 @@ package forestry.core.climate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
@@ -27,6 +27,12 @@ public class ClimatePosition implements IClimatePosition {
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos, NBTTagCompound nbtTag) {
|
||||
this.climateRegion = climateRegion;
|
||||
this.pos = pos;
|
||||
readFromNBT(nbtTag);
|
||||
}
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos) {
|
||||
Biome biome = climateRegion.getWorld().getBiome(pos);
|
||||
this.climateRegion = climateRegion;
|
||||
|
||||
@@ -1,87 +1,148 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
|
||||
protected World world;
|
||||
protected IGreenhouseController controller;
|
||||
protected Map<BlockPos, IClimatePosition> positions;
|
||||
protected List<BlockPos> wallPositions;
|
||||
protected final World world;
|
||||
protected final IGreenhouseControllerInternal controller;
|
||||
protected final Map<BlockPos, IClimatePosition> positions;
|
||||
protected final List<BlockPos> wallPositions;
|
||||
protected final List<IClimateSource> sources;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimateRoom(ClimateRoom oldRoom, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
public ClimateRoom(ClimateRoom oldRoom, Map<BlockPos, IClimatePosition> newPositions, List<BlockPos> newWallPositions) {
|
||||
this.world = oldRoom.getWorld();
|
||||
this.controller = oldRoom.controller;
|
||||
Map<BlockPos, IClimatePosition> newPositions = new HashMap<>();
|
||||
for(Entry<BlockPos, IClimatePosition> positionEntry : innerPositions.entrySet()){
|
||||
IClimatePosition position = oldRoom.getPositions().get(positionEntry.getKey());
|
||||
if(position == null){
|
||||
newPositions.put(positionEntry.getKey(), positionEntry.getValue());
|
||||
}else{
|
||||
newPositions.put(positionEntry.getKey(), position);
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = newWallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
for(Entry<BlockPos, IClimatePosition> positionEntry : newPositions.entrySet()){
|
||||
BlockPos pos = positionEntry.getKey();
|
||||
IClimatePosition position = positionEntry.getValue();
|
||||
IClimatePosition oldPosition = oldRoom.getPositions().get(pos);
|
||||
float temperature = position.getTemperature();
|
||||
float humidity = position.getHumidity();
|
||||
if(oldPosition != null){
|
||||
temperature = oldPosition.getTemperature();
|
||||
humidity = oldPosition.getHumidity();
|
||||
}
|
||||
addPosition(pos, temperature, humidity);
|
||||
}
|
||||
this.positions = newPositions;
|
||||
this.wallPositions = wallPositions;
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = innerPositions;
|
||||
this.wallPositions = wallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, NBTTagCompound nbtTag) {
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, List<BlockPos> wallPositions, NBTTagCompound nbtTag) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = new ArrayList<>();
|
||||
this.sources = new ArrayList<>();
|
||||
readFromNBT(nbtTag);
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
private float getExactTemperature() {
|
||||
float temperature = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IClimatePosition position : this.positions.values()){
|
||||
if(position != null){
|
||||
positions++;
|
||||
temperature+=position.getTemperature();
|
||||
}
|
||||
}
|
||||
return temperature / positions;
|
||||
}
|
||||
|
||||
private float getExactHumidity() {
|
||||
float humidity = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for(IClimatePosition position : this.positions.values()){
|
||||
if(position != null){
|
||||
positions++;
|
||||
humidity+=position.getHumidity();
|
||||
}
|
||||
}
|
||||
return humidity / positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate() {
|
||||
for(Entry<BlockPos, IClimatePosition> position : positions.entrySet()){
|
||||
BlockPos pos = position.getKey();
|
||||
if(world.isBlockLoaded(pos)){
|
||||
updateSides(pos);
|
||||
if(!controller.isAssembled()){
|
||||
Biome biome = world.getBiome(pos);
|
||||
public void updateClimate(int ticks) {
|
||||
for(IClimateSource source : sources){
|
||||
if(source != null){
|
||||
if(ticks % source.getTicksForChange(this) == 0){
|
||||
source.changeClimate(ticks, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ticks % getTicksPerUpdate() == 0){
|
||||
for(Entry<BlockPos, IClimatePosition> position : positions.entrySet()){
|
||||
BlockPos pos = position.getKey();
|
||||
if(world.isBlockLoaded(pos)){
|
||||
updateSides(pos);
|
||||
|
||||
float biomeTemperature = biome.getTemperature();
|
||||
float biomeHumidity = biome.getRainfall();
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if(climatedInfo.getTemperature() != biomeTemperature){
|
||||
if(climatedInfo.getTemperature() > biomeTemperature){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addTemperature(0.01F);
|
||||
if(!controller.isAssembled()){
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if(climatedInfo.getTemperature() != climateControl.getControlTemperature()){
|
||||
if(climatedInfo.getTemperature() > climateControl.getControlTemperature()){
|
||||
climatedInfo.addTemperature(-Math.min(0.01F, climatedInfo.getTemperature() - climateControl.getControlTemperature()));
|
||||
}else{
|
||||
climatedInfo.addTemperature(Math.min(0.01F, climateControl.getControlTemperature() - climatedInfo.getTemperature()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(climatedInfo.getHumidity() != biomeHumidity){
|
||||
if(climatedInfo.getHumidity() > biomeHumidity){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addHumidity(0.01F);
|
||||
if(climatedInfo.getHumidity() != climateControl.getControlHumidity()){
|
||||
if(climatedInfo.getHumidity() > climateControl.getControlHumidity()){
|
||||
climatedInfo.addHumidity(-Math.min(0.01F, climatedInfo.getHumidity() - climateControl.getControlHumidity()));
|
||||
}else{
|
||||
climatedInfo.addHumidity(Math.min(0.01F, climateControl.getControlHumidity() - climatedInfo.getHumidity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,44 +150,51 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSides(BlockPos pos){
|
||||
protected void updateSides(BlockPos pos){
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
BlockPos facePos = pos.offset(facing);
|
||||
IClimatePosition climatedInfoFace = positions.get(facePos);
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfoFace.getTemperature() >= 2.0F){
|
||||
if(climatedInfoFace.getTemperature() > 2.0F){
|
||||
climatedInfoFace.setTemperature(2.0F);
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
boolean hasChange = false;
|
||||
if(climateControl.getControlTemperature() != temperature || climateControl.getControlHumidity() != humidity) {
|
||||
boolean updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
boolean updateHum = climatedInfo.getHumidity() >= climateControl.getControlHumidity();
|
||||
if(updateTemp || updateHum){
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
IClimatePosition climatedInfoFace = positions.get(pos.offset(facing));
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getTemperature() - climatedInfoFace.getTemperature());
|
||||
climatedInfo.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
updateTemp = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
float change = Math.min(0.01F, climatedInfo.getHumidity() - climatedInfoFace.getHumidity());
|
||||
climatedInfo.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
updateHum = climatedInfo.getTemperature() >= climateControl.getControlTemperature();
|
||||
hasChange = true;
|
||||
}
|
||||
if(!updateTemp && !updateHum){
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}else if(climatedInfoFace.getTemperature() <= 0.0F){
|
||||
if(climatedInfoFace.getTemperature() < 0.0F){
|
||||
climatedInfoFace.setTemperature(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(climatedInfoFace.getHumidity() >= 2.0F){
|
||||
if(climatedInfoFace.getHumidity() > 2.0F){
|
||||
climatedInfoFace.setHumidity(2.0F);
|
||||
}
|
||||
continue;
|
||||
}else if(climatedInfoFace.getHumidity() <= 0.0F){
|
||||
if(climatedInfoFace.getHumidity() < 0.0F){
|
||||
climatedInfoFace.setHumidity(0.0F);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
climatedInfoFace.addTemperature(0.01F);
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
climatedInfoFace.addHumidity(0.01F);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasChange){
|
||||
temperature = getExactTemperature();
|
||||
humidity = getExactHumidity();
|
||||
}
|
||||
}
|
||||
|
||||
protected IClimateControl getControl(BlockPos pos){
|
||||
if(world.isBlockLoaded(pos)){
|
||||
if(!controller.isAssembled()){
|
||||
return BiomeClimateControl.getControl(world.getBiome(pos));
|
||||
}
|
||||
}
|
||||
return controller.getClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,9 +203,9 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
for(Entry<BlockPos, IClimatePosition> entry : positions.entrySet()){
|
||||
BlockPos pos = entry.getKey();
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("XPos", pos.getX());
|
||||
tag.setInteger("YPos", pos.getY());
|
||||
tag.setInteger("ZPos", pos.getZ());
|
||||
tag.setInteger("X", pos.getX());
|
||||
tag.setInteger("Y", pos.getY());
|
||||
tag.setInteger("Z", pos.getZ());
|
||||
positionList.appendTag(entry.getValue().writeToNBT(tag));
|
||||
}
|
||||
nbt.setTag("Positions", positionList);
|
||||
@@ -149,13 +217,16 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
NBTTagList positionList = nbt.getTagList("Positions", 10);
|
||||
for(int i = 0;i < positionList.tagCount();i++){
|
||||
NBTTagCompound positionTag = positionList.getCompoundTagAt(i);
|
||||
int xPos = positionTag.getInteger("XPos");
|
||||
int yPos = positionTag.getInteger("YPos");
|
||||
int zPos = positionTag.getInteger("ZPos");
|
||||
int xPos = positionTag.getInteger("X");
|
||||
int yPos = positionTag.getInteger("Y");
|
||||
int zPos = positionTag.getInteger("Z");
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
ClimatePosition position = new ClimatePosition(this, pos);
|
||||
position.readFromNBT(positionTag);
|
||||
positions.put(pos, position);
|
||||
IClimatePosition position = positions.get(pos);
|
||||
if(position != null){
|
||||
position.readFromNBT(positionTag);
|
||||
}else{
|
||||
positions.put(pos, new ClimatePosition(this, pos, positionTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +245,35 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
return positions;
|
||||
}
|
||||
|
||||
protected void addPosition(BlockPos pos, float temperature, float humidity){
|
||||
IClimatePosition otherPosition = positions.get(pos);
|
||||
if(otherPosition != null){
|
||||
otherPosition.setHumidity(humidity);
|
||||
otherPosition.setTemperature(temperature);
|
||||
}else{
|
||||
positions.put(pos, new ClimatePosition(this, pos, temperature, humidity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSource(IClimateSource source) {
|
||||
if(!sources.contains(source)){
|
||||
sources.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSource source) {
|
||||
if(sources.contains(source)){
|
||||
sources.remove(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IClimateSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getOtherPositions() {
|
||||
return wallPositions;
|
||||
@@ -190,6 +290,8 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
data.writeFloat(pos.getTemperature());
|
||||
data.writeFloat(pos.getHumidity());
|
||||
}
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
}else{
|
||||
data.writeInt(0);
|
||||
}
|
||||
@@ -199,18 +301,23 @@ public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
int size = data.readInt();
|
||||
if(size != 0){
|
||||
positions = new HashMap<>();
|
||||
positions.clear();;
|
||||
for(int index = 0;index < size;index++){
|
||||
int xPos = data.readInt();
|
||||
int yPos = data.readInt();
|
||||
int zPos = data.readInt();
|
||||
float temperature = data.readFloat();
|
||||
float humidity = data.readFloat();
|
||||
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
positions.put(pos, new ClimatePosition(this, pos, temperature, humidity));
|
||||
addPosition(new BlockPos(data.readInt(), data.readInt(), data.readInt()), data.readFloat(), data.readFloat());
|
||||
}
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateSourceProvider;
|
||||
|
||||
public abstract class ClimateSource<P extends IClimateSourceProvider> implements IClimateSource {
|
||||
|
||||
protected P provider;
|
||||
protected final int ticksForChange;
|
||||
|
||||
public ClimateSource(int ticksForChange) {
|
||||
this.ticksForChange = ticksForChange;
|
||||
}
|
||||
|
||||
public void setProvider(P provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClimate(int tickCount, IClimateRegion region) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksForChange(IClimateRegion region) {
|
||||
return ticksForChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateSourceProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
|
||||
public class ClimatiserDefinition implements IClimatiserDefinition {
|
||||
|
||||
protected final float change;
|
||||
protected final EnumClimatiserModes mode;
|
||||
protected final double range;
|
||||
protected final EnumClimatiserTypes type;
|
||||
|
||||
public ClimatiserDefinition(float change, EnumClimatiserModes mode, double range, EnumClimatiserTypes type) {
|
||||
this.change = change;
|
||||
this.mode = mode;
|
||||
this.range = range;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChange() {
|
||||
return change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumClimatiserTypes getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumClimatiserModes getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.config;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.core.IForestryConstants;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class Constants implements IForestryConstants {
|
||||
@@ -23,6 +22,7 @@ public class Constants implements IForestryConstants {
|
||||
public static final String VERSION = "@VERSION@";
|
||||
public static final String BUILD_NUMBER = "@BUILD_NUMBER@";
|
||||
|
||||
public static final String RF_MOD_ID = "CoFHAPI|energy";
|
||||
public static final String TESLA_MOD_ID = "tesla";
|
||||
|
||||
public static final int FLAG_BLOCK_UPDATE = 1;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package forestry.core.fluids;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
|
||||
public class DrainOnlyFluidHandlerWrapper implements IFluidHandler {
|
||||
@Nonnull
|
||||
private final IFluidHandler internalFluidHandler;
|
||||
|
||||
public DrainOnlyFluidHandlerWrapper(@Nonnull IFluidHandler internalFluidHandler) {
|
||||
this.internalFluidHandler = internalFluidHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties() {
|
||||
IFluidTankProperties[] internalTankProperties = internalFluidHandler.getTankProperties();
|
||||
IFluidTankProperties[] tankProperties = new IFluidTankProperties[internalTankProperties.length];
|
||||
for (int i = 0; i < internalTankProperties.length; i++) {
|
||||
IFluidTankProperties fluidTankProperties = internalTankProperties[i];
|
||||
tankProperties[i] = new DrainOnlyFluidPropertiesWrapper(fluidTankProperties);
|
||||
}
|
||||
return tankProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
return internalFluidHandler.drain(resource, doDrain);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
return internalFluidHandler.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
private static class DrainOnlyFluidPropertiesWrapper implements IFluidTankProperties {
|
||||
@Nonnull
|
||||
private final IFluidTankProperties internalTankProperties;
|
||||
|
||||
public DrainOnlyFluidPropertiesWrapper(@Nonnull IFluidTankProperties internalTankProperties) {
|
||||
this.internalTankProperties = internalTankProperties;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack getContents() {
|
||||
return internalTankProperties.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return internalTankProperties.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain() {
|
||||
return internalTankProperties.canDrain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFillFluidType(FluidStack fluidStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrainFluidType(FluidStack fluidStack) {
|
||||
return internalTankProperties.canDrainFluidType(fluidStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IGenome;
|
||||
|
||||
@@ -14,13 +14,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
@@ -12,10 +12,9 @@ package forestry.core.genetics.mutations;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerCamouflageSprayCan extends ContainerItemInventory<ItemInventoryCamouflageSprayCan> {
|
||||
|
||||
public ContainerCamouflageSprayCan(ItemInventoryCamouflageSprayCan inventory, InventoryPlayer playerInventory) {
|
||||
super(inventory, playerInventory, 8, 84);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,5 +58,9 @@ public abstract class ContainerItemInventory<I extends ItemInventory> extends Co
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public I getItemInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
|
||||
|
||||
if (tile instanceof IPowerHandler) {
|
||||
EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
|
||||
int energyManagerData = energyManager.toGuiInt();
|
||||
int energyManagerData = energyManager.getEnergyStored();
|
||||
if (energyManagerData != previousEnergyManagerData) {
|
||||
PacketGuiEnergy packet = new PacketGuiEnergy(windowId, energyManagerData);
|
||||
sendPacketToListeners(packet);
|
||||
@@ -105,7 +105,7 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
|
||||
public void onGuiEnergy(int energyStored) {
|
||||
if (tile instanceof IPowerHandler) {
|
||||
EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
|
||||
energyManager.fromGuiInt(energyStored);
|
||||
energyManager.setEnergyStored(energyStored);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class GuiCamouflageSprayCan extends GuiForestry<ContainerCamouflageSprayCan, ItemInventoryCamouflageSprayCan> {
|
||||
|
||||
public GuiCamouflageSprayCan(EntityPlayer player, ItemInventoryCamouflageSprayCan inventory) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/camouflageSprayCan.png", new ContainerCamouflageSprayCan(inventory, player.inventory), inventory);
|
||||
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 80, 39, inventory, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
String name = Translator.translateToLocal("for.gui.camouflage.spray.can");
|
||||
textLayout.line = 6;
|
||||
textLayout.drawCenteredLine(name, 0, fontColor.get("gui.title"));
|
||||
bindTexture(textureFile);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,17 +15,6 @@ import java.awt.Rectangle;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.core.IErrorSource;
|
||||
import forestry.core.config.Config;
|
||||
@@ -35,11 +24,22 @@ import forestry.core.gui.ledgers.LedgerManager;
|
||||
import forestry.core.gui.ledgers.OwnerLedger;
|
||||
import forestry.core.gui.ledgers.PowerLedger;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.FontColour;
|
||||
import forestry.core.render.ForestryResource;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.core.tiles.IPowerHandler;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class GuiForestry<C extends Container, I extends IInventory> extends GuiContainer {
|
||||
protected final I inventory;
|
||||
@@ -94,8 +94,13 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
ledgerManager.add(new ClimateLedger(ledgerManager, (IClimatised) inventory));
|
||||
}
|
||||
|
||||
if (Config.enableEnergyStat && inventory instanceof IPowerHandler && ((IPowerHandler) inventory).getEnergyManager().getMaxEnergyStored() > 0) {
|
||||
ledgerManager.add(new PowerLedger(ledgerManager, (IPowerHandler) inventory));
|
||||
if (Config.enableEnergyStat) {
|
||||
if (inventory instanceof IPowerHandler && !(inventory instanceof TileEngine)) {
|
||||
IPowerHandler powerHandler = (IPowerHandler) this.inventory;
|
||||
if (powerHandler.getEnergyManager().getMaxEnergyStored() > 0) {
|
||||
ledgerManager.add(new PowerLedger(ledgerManager, powerHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.enableHints && inventory instanceof IHintSource) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import forestry.apiculture.multiblock.TileAlvearySieve;
|
||||
import forestry.apiculture.tiles.TileApiary;
|
||||
import forestry.apiculture.tiles.TileBeeHouse;
|
||||
import forestry.core.items.ItemAlyzer;
|
||||
import forestry.core.items.ItemCamouflageSprayCan;
|
||||
import forestry.core.items.ItemSolderingIron;
|
||||
import forestry.core.tiles.TileAnalyzer;
|
||||
import forestry.core.tiles.TileEscritoire;
|
||||
@@ -105,7 +106,8 @@ public class GuiIdRegistry {
|
||||
ItemImprinter.class,
|
||||
ItemInfuser.class,
|
||||
ItemLetter.class,
|
||||
ItemSolderingIron.class
|
||||
ItemSolderingIron.class,
|
||||
ItemCamouflageSprayCan.class
|
||||
));
|
||||
|
||||
registerGuiHandlers(GuiType.Entity, Arrays.asList(
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import forestry.core.tiles.ILocatable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public interface IGuiHandlerTile extends IGuiHandlerForestry, ILocatable {
|
||||
Object getGui(EntityPlayer player, int data);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class PowerLedger extends Ledger {
|
||||
drawHeader(Translator.translateToLocal("for.gui.energy"), xHeader, y + 8);
|
||||
|
||||
drawSubheader(Translator.translateToLocal("for.gui.stored") + ':', xBody, y + 20);
|
||||
drawText(energyManager.getTotalEnergyStored() + " RF", xBody, y + 32);
|
||||
drawText(energyManager.getEnergyStored() + " RF", xBody, y + 32);
|
||||
|
||||
drawSubheader(Translator.translateToLocal("for.gui.maxenergy") + ':', xBody, y + 44);
|
||||
drawText(energyManager.getMaxEnergyStored() + " RF", xBody, y + 56);
|
||||
@@ -56,7 +56,7 @@ public class PowerLedger extends Ledger {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return tile.getEnergyManager().getTotalEnergyStored() + " RF";
|
||||
return tile.getEnergyManager().getEnergyStored() + " RF";
|
||||
}
|
||||
|
||||
}
|
||||
+3
-5
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.gui.widgets;
|
||||
package forestry.core.gui.widgets;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -25,8 +25,6 @@ import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflageItemHandler;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
@@ -65,8 +63,8 @@ public class WidgetCamouflageSlot extends Widget {
|
||||
if (stack != null) {
|
||||
if (!CamouflageManager.camouflageAccess.isItemBlackListed(type, stack)) {
|
||||
for(ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getCamouflageItemHandler(type)){
|
||||
if(handler != null && handler.canHandle(stack, camouflageHandler)){
|
||||
camouflageHandler.setCamouflageBlock(type, stack.copy());
|
||||
if(handler != null && handler.canHandle(stack)){
|
||||
camouflageHandler.setCamouflageBlock(handler.getType(), stack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package forestry.core.inventory;
|
||||
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.core.network.packets.CamouflageSelectionType;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemInventoryCamouflageSprayCan extends ItemInventory implements ICamouflageHandler {
|
||||
|
||||
public ItemInventoryCamouflageSprayCan(EntityPlayer player, ItemStack parent) {
|
||||
super(player, 1, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCamouflageBlock(String type) {
|
||||
return getStackInSlot(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDefaultCamouflageBlock(String type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandleType(String type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCamouflageBlock(String type, ItemStack camouflageBlock) {
|
||||
if(!ItemStackUtil.isIdenticalItem(camouflageBlock, getStackInSlot(0))){
|
||||
setInventorySlotContents(0, camouflageBlock);
|
||||
|
||||
World world = player.worldObj;
|
||||
if (world != null && world.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.ITEM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
return new BlockPos(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorldObj() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ package forestry.core.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.blocks.IBlockRotatable;
|
||||
import forestry.core.blocks.IBlockWithMeta;
|
||||
import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
@@ -77,8 +77,8 @@ public class ItemBlockForestry<B extends Block> extends ItemBlock {
|
||||
}
|
||||
}
|
||||
|
||||
if (block instanceof BlockBase) {
|
||||
((BlockBase) block).rotateAfterPlacement(player, world, pos, side);
|
||||
if (block instanceof IBlockRotatable) {
|
||||
((IBlockRotatable) block).rotateAfterPlacement(player, world, pos, side);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package forestry.core.items;
|
||||
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.gui.ContainerCamouflageSprayCan;
|
||||
import forestry.core.gui.GuiCamouflageSprayCan;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemCamouflageSprayCan extends ItemWithGui {
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new GuiCamouflageSprayCan(player, new ItemInventoryCamouflageSprayCan(player, heldItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return new ContainerCamouflageSprayCan(new ItemInventoryCamouflageSprayCan(player, heldItem), player.inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
super.registerModel(item, manager);
|
||||
ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:camouflageSprayCanFilled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
|
||||
ItemInventoryCamouflageSprayCan inventory = new ItemInventoryCamouflageSprayCan(player, stack);
|
||||
ItemStack camouflage = inventory.getStackInSlot(0);
|
||||
if(camouflage != null){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) tile;
|
||||
String type = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflage).getType();
|
||||
if(type != null && handler.canHandleType(type)){
|
||||
if(world.isRemote){
|
||||
handler.setCamouflageBlock(type, camouflage);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
||||
if (!worldIn.isRemote && playerIn.isSneaking()) {
|
||||
openGui(playerIn);
|
||||
}
|
||||
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,6 +89,9 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
public final ItemForestry refractoryWax;
|
||||
public final ItemFruit fruits;
|
||||
|
||||
/* Camouflage */
|
||||
public final ItemCamouflageSprayCan camouflageSprayCan;
|
||||
|
||||
public ItemRegistryCore() {
|
||||
fertilizerBio = registerItem(new ItemForestry(), "fertilizerBio");
|
||||
fertilizerCompound = registerItem(new ItemFertilizer(), "fertilizerCompound");
|
||||
@@ -186,6 +189,9 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
ItemStack fruit = new ItemStack(fruits, 1, def.ordinal());
|
||||
OreDictionary.registerOre(def.getOreDict(), fruit);
|
||||
}
|
||||
|
||||
// CAMOUFLAGE
|
||||
camouflageSprayCan = registerItem(new ItemCamouflageSprayCan(), "camouflageSprayCan");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package forestry.core.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelCamouflageSprayCan extends BlankModel {
|
||||
|
||||
@Override
|
||||
protected ItemOverrideList createOverrides() {
|
||||
return new SprayCanOverrideList();
|
||||
}
|
||||
|
||||
private class SprayCanOverrideList extends ItemOverrideList{
|
||||
|
||||
public SprayCanOverrideList() {
|
||||
super(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
|
||||
IModel basicModel = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forestry:item/camouflageSprayCan"));
|
||||
IBakedModel model = basicModel.bake(basicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
IBakedModel filledModel = basicModel.bake(basicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
IBakedModel camouflageModel = null;
|
||||
|
||||
if(stack.hasTagCompound() && entity instanceof EntityPlayer){
|
||||
ItemInventoryCamouflageSprayCan inventory = new ItemInventoryCamouflageSprayCan((EntityPlayer) entity, stack);
|
||||
ItemStack camouflage = inventory.getStackInSlot(0);
|
||||
if(camouflage != null){
|
||||
IModel filledBasicModel = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forestry:item/camouflageSprayCanFilled"));
|
||||
filledModel = filledBasicModel.bake(filledBasicModel.getDefaultState(), DefaultVertexFormats.ITEM, new DefaultTextureGetter());
|
||||
|
||||
camouflageModel = new TRSRBakedModel(Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(camouflage), -0.0625F * 3, 0.0625F * 3, 0.0625F, 0.5F);
|
||||
}
|
||||
|
||||
}
|
||||
return new SprayCanModel(model, filledModel, camouflageModel, ModelManager.getInstance().DEFAULT_ITEM);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SprayCanModel extends BlankModel implements IPerspectiveAwareModel{
|
||||
|
||||
private final IBakedModel originalModel;
|
||||
private final IBakedModel camouflageModel;
|
||||
private final IModelState state;
|
||||
private final IBakedModel filledModel;
|
||||
|
||||
public SprayCanModel(IBakedModel originalModel, IBakedModel filledModel, IBakedModel camouflageModel, IModelState state) {
|
||||
this.originalModel = originalModel;
|
||||
this.filledModel = filledModel;
|
||||
this.camouflageModel = camouflageModel;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
quads.addAll(filledModel.getQuads(state, side, rand));
|
||||
if(camouflageModel != null){
|
||||
quads.addAll(camouflageModel.getQuads(state, side, rand));
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) {
|
||||
if(cameraTransformType == TransformType.GUI){
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
}
|
||||
return IPerspectiveAwareModel.MapWrapper.handlePerspective(originalModel, state, cameraTransformType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ package forestry.core.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -24,7 +26,7 @@ import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -13,6 +13,8 @@ package forestry.core.multiblock;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -22,7 +24,6 @@ import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.api.multiblock.MultiblockTileEntityBase;
|
||||
import forestry.core.config.Constants;
|
||||
@@ -31,7 +32,6 @@ import forestry.core.gui.IGuiHandlerTile;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.tiles.IFilterSlotDelegate;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
|
||||
public abstract class MultiblockTileEntityForestry<T extends IMultiblockLogic> extends MultiblockTileEntityBase<T> implements ISidedInventory, IFilterSlotDelegate, ILocatable, IGuiHandlerTile {
|
||||
|
||||
@@ -26,6 +26,7 @@ public enum PacketIdClient implements IPacketId {
|
||||
GUI_LAYOUT_SELECT,
|
||||
GUI_ENERGY,
|
||||
SOCKET_UPDATE,
|
||||
CAMOUFLAGE_SELECTION,
|
||||
|
||||
// Core Tile Entities
|
||||
TILE_FORESTRY_UPDATE,
|
||||
|
||||
@@ -23,15 +23,14 @@ public enum PacketIdServer implements IPacketId {
|
||||
PIPETTE_CLICK,
|
||||
CHIPSET_CLICK,
|
||||
SOLDERING_IRON_CLICK,
|
||||
CAMOUFLAGE_SELECTION,
|
||||
CLIMATE_CONTROL_UPDATE,
|
||||
|
||||
// JEI
|
||||
WORKTABLE_RECIPE_REQUEST,
|
||||
|
||||
// Apiculture
|
||||
BEE_LOGIC_ACTIVE_ENTITY_REQUEST,
|
||||
|
||||
//Greenhouse
|
||||
TILE_FORESTRY_CAMOUFLAGE,
|
||||
|
||||
// Mail
|
||||
LETTER_INFO_REQUEST,
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import forestry.core.network.packets.PacketCamouflageSelectClient;
|
||||
import forestry.core.network.packets.PacketCamouflageSelectServer;
|
||||
import forestry.core.network.packets.PacketChipsetClick;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
@@ -26,6 +28,7 @@ import forestry.core.network.packets.PacketSocketUpdate;
|
||||
import forestry.core.network.packets.PacketSolderingIronClick;
|
||||
import forestry.core.network.packets.PacketTankLevelUpdate;
|
||||
import forestry.core.network.packets.PacketTileStream;
|
||||
import forestry.core.network.packets.PacketUpdateClimateControl;
|
||||
|
||||
public class PacketRegistryCore extends PacketRegistry {
|
||||
@Override
|
||||
@@ -42,10 +45,13 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
registerClientPacket(new PacketFXSignal());
|
||||
registerClientPacket(new PacketTankLevelUpdate());
|
||||
registerClientPacket(new PacketGenomeTrackerSync());
|
||||
registerClientPacket(new PacketCamouflageSelectClient());
|
||||
|
||||
registerServerPacket(new PacketGuiSelectRequest());
|
||||
registerServerPacket(new PacketPipetteClick());
|
||||
registerServerPacket(new PacketChipsetClick());
|
||||
registerServerPacket(new PacketSolderingIronClick());
|
||||
registerServerPacket(new PacketCamouflageSelectServer());
|
||||
registerServerPacket(new PacketUpdateClimateControl());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package forestry.core.network.packets;
|
||||
|
||||
public enum CamouflageSelectionType {
|
||||
TILE, MULTIBLOCK, ITEM;
|
||||
|
||||
public static final CamouflageSelectionType[] VALUES = values();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*******************************************************************************
|
||||
* 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.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
|
||||
public class PacketCamouflageSelectClient extends PacketCoordinates implements IForestryPacketClient{
|
||||
|
||||
private ItemStack camouflageStack;
|
||||
private String camouflageType;
|
||||
private CamouflageSelectionType selectionType;
|
||||
|
||||
public PacketCamouflageSelectClient() {
|
||||
}
|
||||
|
||||
public PacketCamouflageSelectClient(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) {
|
||||
super(handler.getCoordinates());
|
||||
this.camouflageStack = handler.getCamouflageBlock(camouflageType);
|
||||
this.selectionType = selectionType;
|
||||
this.camouflageType = camouflageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdClient getPacketId() {
|
||||
return PacketIdClient.CAMOUFLAGE_SELECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(selectionType.ordinal());
|
||||
data.writeBoolean(camouflageType != null);
|
||||
if(camouflageType != null){
|
||||
data.writeUTF(camouflageType);
|
||||
}
|
||||
data.writeItemStack(camouflageStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
selectionType = CamouflageSelectionType.values()[data.readShort()];
|
||||
if(data.readBoolean()){
|
||||
camouflageType = data.readUTF();
|
||||
}
|
||||
camouflageStack = data.readItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
ICamouflageHandler handler = null;
|
||||
if(selectionType == CamouflageSelectionType.MULTIBLOCK){
|
||||
if (tile instanceof IMultiblockComponent) {
|
||||
IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController();
|
||||
|
||||
if (controller instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) controller;
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
for (IMultiblockComponent comp : controller.getComponents()) {
|
||||
if (comp instanceof ICamouflagedTile) {
|
||||
ICamouflagedTile camBlock = (ICamouflagedTile) comp;
|
||||
if (camouflageType != null && camBlock.getCamouflageType() != null && camBlock.getCamouflageType().equals(camouflageType)) {
|
||||
player.worldObj.markBlockRangeForRenderUpdate(camBlock.getCoordinates(), camBlock.getCoordinates());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(selectionType == CamouflageSelectionType.TILE){
|
||||
if (tile instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) tile;
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
player.worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************
|
||||
* 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.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.gui.ContainerCamouflageSprayCan;
|
||||
import forestry.core.inventory.ItemInventoryCamouflageSprayCan;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketCamouflageSelectServer extends PacketCoordinates implements IForestryPacketServer{
|
||||
|
||||
private ItemStack camouflageStack;
|
||||
private String camouflageType;
|
||||
private CamouflageSelectionType selectionType;
|
||||
|
||||
public PacketCamouflageSelectServer() {
|
||||
}
|
||||
|
||||
public PacketCamouflageSelectServer(ICamouflageHandler handler, String camouflageType, CamouflageSelectionType selectionType) {
|
||||
super(handler.getCoordinates());
|
||||
this.camouflageStack = handler.getCamouflageBlock(camouflageType);
|
||||
this.selectionType = selectionType;
|
||||
this.camouflageType = camouflageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.CAMOUFLAGE_SELECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(selectionType.ordinal());
|
||||
data.writeBoolean(camouflageType != null);
|
||||
if(camouflageType != null){
|
||||
data.writeUTF(camouflageType);
|
||||
}
|
||||
data.writeItemStack(camouflageStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
selectionType = CamouflageSelectionType.values()[data.readShort()];
|
||||
if(data.readBoolean()){
|
||||
camouflageType = data.readUTF();
|
||||
}
|
||||
camouflageStack = data.readItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
ICamouflageHandler handler = null;
|
||||
if(selectionType == CamouflageSelectionType.MULTIBLOCK){
|
||||
if (tile instanceof IMultiblockComponent) {
|
||||
IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController();
|
||||
|
||||
if (controller instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) controller;
|
||||
}
|
||||
|
||||
}
|
||||
}else if(selectionType == CamouflageSelectionType.TILE){
|
||||
if (tile instanceof ICamouflageHandler) {
|
||||
handler = (ICamouflageHandler) tile;
|
||||
}
|
||||
}else{
|
||||
if(player.openContainer instanceof ContainerCamouflageSprayCan){
|
||||
ContainerCamouflageSprayCan container = (ContainerCamouflageSprayCan) player.openContainer;
|
||||
ItemInventoryCamouflageSprayCan itemInventoryCamouflageSprayCan = container.getItemInventory();
|
||||
if(itemInventoryCamouflageSprayCan != null){
|
||||
handler = itemInventoryCamouflageSprayCan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handler != null) {
|
||||
handler.setCamouflageBlock(camouflageType, camouflageStack);
|
||||
if(selectionType != CamouflageSelectionType.ITEM){
|
||||
Proxies.net.sendNetworkPacket(new PacketCamouflageSelectClient(handler, camouflageType, selectionType), player.worldObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
@@ -21,7 +23,6 @@ import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
|
||||
public class PacketGuiUpdate extends PacketCoordinates implements IForestryPacketClient {
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketUpdateClimateControl extends PacketCoordinates implements IForestryPacketServer {
|
||||
|
||||
private float controlTemperature;
|
||||
private float controlHumidity;
|
||||
|
||||
public PacketUpdateClimateControl() {
|
||||
}
|
||||
|
||||
public PacketUpdateClimateControl(IClimateControlProvider provider) {
|
||||
super(provider.getCoordinates());
|
||||
|
||||
IClimateControl control = provider.getClimateControl();
|
||||
controlTemperature = control.getControlTemperature();
|
||||
controlHumidity = control.getControlHumidity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeFloat(controlTemperature);
|
||||
data.writeFloat(controlHumidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
controlTemperature = data.readFloat();
|
||||
controlHumidity = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.CLIMATE_CONTROL_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
IClimateControl control = null;
|
||||
if(tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
IMultiblockLogic logic = component.getMultiblockLogic();
|
||||
if(logic.isConnected() && logic.getController() instanceof IClimateControlProvider){
|
||||
control = ((IClimateControlProvider) logic.getController()).getClimateControl();
|
||||
}
|
||||
}else if(tile instanceof IClimateControlProvider){
|
||||
control = ((IClimateControlProvider) tile).getClimateControl();
|
||||
}
|
||||
if(control != null){
|
||||
control.setControlTemperature(controlTemperature);
|
||||
control.setControlHumidity(controlHumidity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
@@ -12,8 +12,6 @@ package forestry.core.tiles;
|
||||
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
public interface IPowerHandler extends IEnergyHandler {
|
||||
public interface IPowerHandler {
|
||||
EnergyManager getEnergyManager();
|
||||
}
|
||||
@@ -14,13 +14,6 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.blocks.BlockBase;
|
||||
@@ -30,13 +23,19 @@ import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import forestry.energy.EnergyTransferMode;
|
||||
import forestry.energy.compat.rf.IEnergyConnectionDelegated;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileEngine extends TileBase implements IEnergyConnection, IActivatable {
|
||||
public abstract class TileEngine extends TileBase implements IEnergyConnectionDelegated, IActivatable {
|
||||
private static final int CANT_SEND_ENERGY_TIME = 20;
|
||||
|
||||
private boolean active = false; // Used for smp.
|
||||
@@ -63,14 +62,11 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
this.maxHeat = maxHeat;
|
||||
energyManager = new EnergyManager(2000, maxEnergy);
|
||||
|
||||
// allow engines to chain, but not have energy sucked out of them
|
||||
energyManager.setReceiveOnly();
|
||||
energyManager.setExternalMode(EnergyTransferMode.EXTRACT);
|
||||
|
||||
hints.addAll(Config.hints.get("engine"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void addHeat(int i) {
|
||||
heat += i;
|
||||
|
||||
@@ -133,7 +129,7 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
|
||||
progress += pistonSpeedServer;
|
||||
|
||||
energyManager.sendEnergy(facing, tile);
|
||||
EnergyHelper.sendEnergy(energyManager, facing, tile);
|
||||
|
||||
if (progress > 0.25 && stagePiston == 1) {
|
||||
stagePiston = 2;
|
||||
@@ -141,8 +137,8 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
progress = 0;
|
||||
stagePiston = 0;
|
||||
}
|
||||
} else if (enabledRedstone && BlockUtil.isEnergyReceiverOrEngine(facing.getOpposite(), tile)) {
|
||||
if (energyManager.canSendEnergy(facing, tile)) {
|
||||
} else if (enabledRedstone && EnergyHelper.isEnergyReceiverOrEngine(facing.getOpposite(), tile)) {
|
||||
if (EnergyHelper.canSendEnergy(energyManager, facing, tile)) {
|
||||
stagePiston = 1; // If we can transfer energy, start running
|
||||
setActive(true);
|
||||
cantSendEnergyCountdown = CANT_SEND_ENERGY_TIME;
|
||||
@@ -288,11 +284,6 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
@Deprecated //use packets
|
||||
public abstract void sendGUINetworkData(Container containerEngine, IContainerListener iCrafting);
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
public EnergyManager getEnergyManager() {
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -27,6 +30,7 @@ import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.packets.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.NBTUtilForestry;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -40,6 +44,7 @@ import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
|
||||
@@ -14,9 +14,6 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.core.circuits.ISpeedUpgradable;
|
||||
import forestry.core.config.Config;
|
||||
@@ -25,13 +22,17 @@ import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.render.TankRenderInfo;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.energy.EnergyTransferMode;
|
||||
import forestry.energy.compat.rf.IEnergyHandlerDelegated;
|
||||
import forestry.energy.compat.rf.IEnergyReceiverDelegated;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
//@Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles")
|
||||
public abstract class TilePowered extends TileBase implements IRenderableTile, IEnergyReceiver, IPowerHandler, ISpeedUpgradable, IStreamableGui {
|
||||
public abstract class TilePowered extends TileBase implements IRenderableTile, IEnergyReceiverDelegated, IEnergyHandlerDelegated, ISpeedUpgradable, IStreamableGui {
|
||||
private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks
|
||||
|
||||
private final EnergyManager energyManager;
|
||||
@@ -49,7 +50,7 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
protected TilePowered(String hintKey, int maxTransfer, int capacity) {
|
||||
super(hintKey);
|
||||
this.energyManager = new EnergyManager(maxTransfer, capacity);
|
||||
this.energyManager.setReceiveOnly();
|
||||
this.energyManager.setExternalMode(EnergyTransferMode.RECEIVE);
|
||||
|
||||
this.ticksPerWorkCycle = 4;
|
||||
|
||||
@@ -73,7 +74,7 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
}
|
||||
|
||||
public void setEnergyPerWorkCycle(int energyPerWorkCycle) {
|
||||
this.energyPerWorkCycle = EnergyManager.scaleForDifficulty(energyPerWorkCycle);
|
||||
this.energyPerWorkCycle = EnergyHelper.scaleForDifficulty(energyPerWorkCycle);
|
||||
}
|
||||
|
||||
public int getEnergyPerWorkCycle() {
|
||||
@@ -117,7 +118,7 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
|
||||
if (workCounter < ticksPerWorkCycle) {
|
||||
int energyPerWorkCycle = getEnergyPerWorkCycle();
|
||||
boolean consumedEnergy = energyManager.consumeEnergyToDoWork(ticksPerWorkCycle, energyPerWorkCycle);
|
||||
boolean consumedEnergy = EnergyHelper.consumeEnergyToDoWork(energyManager, ticksPerWorkCycle, energyPerWorkCycle);
|
||||
if (consumedEnergy) {
|
||||
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
|
||||
workCounter++;
|
||||
@@ -201,26 +202,6 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
return energyManager.receiveEnergy(from, maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return energyManager.getEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return energyManager.getMaxEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
|
||||
@@ -14,12 +14,8 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.BlockOldLog;
|
||||
@@ -30,7 +26,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -50,22 +45,6 @@ public abstract class BlockUtil {
|
||||
return blockState.getBlock().getDrops(world, posBlock, blockState, 0);
|
||||
|
||||
}
|
||||
|
||||
public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) {
|
||||
if (tile != null) {
|
||||
if (EnergyManager.TESLA_CONSUMER != null) {
|
||||
if (tile.hasCapability(EnergyManager.TESLA_CONSUMER, side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof IEnergyReceiver || (tile instanceof TileEngine)) {
|
||||
IEnergyConnection receptor = (IEnergyConnection) tile;
|
||||
return receptor.canConnectEnergy(side);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean tryPlantCocoaPod(World world, BlockPos pos) {
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -58,23 +59,22 @@ public class CamouflageUtil {
|
||||
}
|
||||
|
||||
public static ICamouflageHandler getCamouflageHandler(IBlockAccess world, BlockPos pos){
|
||||
if(pos == null){
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof ICamouflagedTile){
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
ItemStack camouflageStack = null;
|
||||
ICamouflageHandler handler = null;
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) tile;
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
}
|
||||
if(camouflageStack == null && tile instanceof IMultiblockComponent){
|
||||
if((handler == null || handler.getCamouflageBlock(type) == null) && tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
if(component.getMultiblockLogic().getController() instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) component.getMultiblockLogic().getController();
|
||||
IMultiblockController controller = component.getMultiblockLogic().getController();
|
||||
if(controller instanceof ICamouflageHandler){
|
||||
handler = (ICamouflageHandler) controller;
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
@@ -83,7 +83,7 @@ public class CamouflageUtil {
|
||||
}
|
||||
|
||||
public static ItemStack getCamouflageBlock(IBlockAccess world, BlockPos pos){
|
||||
if(pos == null){
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
@@ -91,18 +91,26 @@ public class CamouflageUtil {
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
ItemStack camouflageStack = null;
|
||||
ICamouflageHandler tileHandler = null;
|
||||
ICamouflageHandler multiblockHandler = null;
|
||||
if(tile instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) tile;
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
tileHandler = (ICamouflageHandler) tile;
|
||||
camouflageStack = tileHandler.getCamouflageBlock(type);
|
||||
}
|
||||
if(camouflageStack == null && tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
if(component.getMultiblockLogic().getController() instanceof ICamouflageHandler){
|
||||
ICamouflageHandler handler = (ICamouflageHandler) component.getMultiblockLogic().getController();
|
||||
camouflageStack = handler.getCamouflageBlock(type);
|
||||
if(camouflageStack == null){
|
||||
camouflageStack = handler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
IMultiblockController controller = component.getMultiblockLogic().getController();
|
||||
if(controller.isAssembled() && controller instanceof ICamouflageHandler){
|
||||
multiblockHandler = (ICamouflageHandler) controller;
|
||||
camouflageStack = multiblockHandler.getCamouflageBlock(type);
|
||||
}
|
||||
}
|
||||
if(camouflageStack == null){
|
||||
if(tileHandler != null){
|
||||
camouflageStack = tileHandler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
if(multiblockHandler != null && camouflageStack == null){
|
||||
camouflageStack = multiblockHandler.getDefaultCamouflageBlock(type);
|
||||
}
|
||||
}
|
||||
return camouflageStack;
|
||||
|
||||
@@ -43,10 +43,21 @@ public abstract class ModUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a specific API is loaded.
|
||||
*
|
||||
* @param apiName the package name of the package-info.java file to check. (for example "cofh.api.energy")
|
||||
*/
|
||||
public static boolean isAPILoaded(String apiName) {
|
||||
return isAPILoaded(apiName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if an API within a specific version range is loaded.
|
||||
*
|
||||
* @param apiName the package name of the package-info.java file to check. (for example "cofh.api.energy")
|
||||
* @param versionRangeString the version range, as defined in {@link VersionParser}.
|
||||
*/
|
||||
public static boolean isAPILoaded(String apiName, String versionRangeString) {
|
||||
Package apiPackage = Package.getPackage(apiName);
|
||||
if (apiPackage == null) {
|
||||
|
||||
@@ -66,4 +66,8 @@ public class OreDictUtil {
|
||||
public static final String GEM_QUARTZ = "gemQuartz";
|
||||
public static final String CHEST_WOOD = "chestWood";
|
||||
public static final String LEATHER = "leather";
|
||||
|
||||
public static final String DYE_YELLOW = "dyeYellow";
|
||||
public static final String DYE_BLUE = "dyeBlue";
|
||||
public static final String DYE_RED = "dyeRed";
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package forestry.energy;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.energy.compat.rf.RFHelper;
|
||||
import forestry.energy.compat.tesla.TeslaHelper;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
public class EnergyHelper {
|
||||
public static int scaleForDifficulty(int energyValue) {
|
||||
float energyModifier = ForestryAPI.activeMode.getFloatSetting("energy.demand.modifier");
|
||||
return Math.round(energyValue * energyModifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes one work cycle's worth of energy.
|
||||
*
|
||||
* @return true if the energy to do work was consumed
|
||||
*/
|
||||
public static boolean consumeEnergyToDoWork(EnergyManager energyManager, int ticksPerWorkCycle, int energyPerWorkCycle) {
|
||||
int energyPerCycle = (int) Math.ceil(energyPerWorkCycle / (float) ticksPerWorkCycle);
|
||||
if (energyManager.getEnergyStored() < energyPerCycle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
energyManager.drainEnergy(energyPerCycle);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends as much energy as it can to the tile at orientation.
|
||||
* For power sources.
|
||||
*
|
||||
* @return amount sent
|
||||
*/
|
||||
public static int sendEnergy(EnergyManager energyManager, EnumFacing orientation, TileEntity tile) {
|
||||
return sendEnergy(energyManager, orientation, tile, Integer.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends amount of energy to the tile at orientation.
|
||||
* For power sources.
|
||||
*
|
||||
* @return amount sent
|
||||
*/
|
||||
public static int sendEnergy(EnergyManager energyManager, EnumFacing orientation, TileEntity tile, int amount, boolean simulate) {
|
||||
if (tile != null) {
|
||||
int extractable = energyManager.extractEnergy(amount, true);
|
||||
if (extractable > 0) {
|
||||
final int sent;
|
||||
EnumFacing side = orientation.getOpposite();
|
||||
if (tile instanceof TileEngine) { // engine chaining
|
||||
TileEngine receptor = (TileEngine) tile;
|
||||
sent = receptor.getEnergyManager().receiveEnergy(extractable, simulate);
|
||||
} else if (tile.hasCapability(CapabilityEnergy.ENERGY, side)) {
|
||||
IEnergyStorage energyStorage = tile.getCapability(CapabilityEnergy.ENERGY, side);
|
||||
sent = energyStorage.receiveEnergy(extractable, simulate);
|
||||
} else if (TeslaHelper.isEnergyReceiver(tile, side)) {
|
||||
sent = TeslaHelper.sendEnergy(tile, side, extractable, simulate);
|
||||
} else if (RFHelper.isEnergyReceiver(tile, side)) {
|
||||
sent = RFHelper.sendEnergy(tile, side, extractable, simulate);
|
||||
} else {
|
||||
sent = 0;
|
||||
}
|
||||
|
||||
energyManager.extractEnergy(sent, simulate);
|
||||
return sent;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this can send energy to the target tile
|
||||
*/
|
||||
public static boolean canSendEnergy(EnergyManager energyManager, EnumFacing orientation, TileEntity tile) {
|
||||
return sendEnergy(energyManager, orientation, tile, Integer.MAX_VALUE, true) > 0;
|
||||
}
|
||||
|
||||
public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) {
|
||||
if (tile != null) {
|
||||
if (tile instanceof TileEngine) { // engine chaining
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tile.hasCapability(CapabilityEnergy.ENERGY, side)) {
|
||||
IEnergyStorage energyStorage = tile.getCapability(CapabilityEnergy.ENERGY, side);
|
||||
return energyStorage.canReceive();
|
||||
}
|
||||
|
||||
if (TeslaHelper.isEnergyReceiver(tile, side)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RFHelper.isEnergyReceiver(tile, side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,296 +1,136 @@
|
||||
package forestry.energy;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.darkhax.tesla.api.ITeslaConsumer;
|
||||
import net.darkhax.tesla.api.ITeslaHolder;
|
||||
import net.darkhax.tesla.api.ITeslaProducer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.energy.compat.EnergyStorageWrapper;
|
||||
import forestry.energy.compat.tesla.TeslaConsumerWrapper;
|
||||
import forestry.energy.compat.tesla.TeslaHelper;
|
||||
import forestry.energy.compat.tesla.TeslaHolderWrapper;
|
||||
import forestry.energy.compat.tesla.TeslaProducerWrapper;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.EnergyStorage;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaConsumer", modid = Constants.TESLA_MOD_ID),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaProducer", modid = Constants.TESLA_MOD_ID),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaHolder", modid = Constants.TESLA_MOD_ID)
|
||||
})
|
||||
public class EnergyManager implements IEnergyReceiver, ITeslaConsumer, ITeslaProducer, ITeslaHolder, IEnergyProvider, IStreamable {
|
||||
@CapabilityInject(ITeslaConsumer.class)
|
||||
public static Capability<ITeslaConsumer> TESLA_CONSUMER = null;
|
||||
@CapabilityInject(ITeslaProducer.class)
|
||||
public static Capability<ITeslaProducer> TESLA_PRODUCER = null;
|
||||
@CapabilityInject(ITeslaHolder.class)
|
||||
public static Capability<ITeslaHolder> TESLA_HOLDER = null;
|
||||
|
||||
private enum EnergyTransferMode {
|
||||
EXTRACT, RECEIVE, BOTH
|
||||
}
|
||||
|
||||
private final EnergyStorage energyStorage;
|
||||
private EnergyTransferMode mode = EnergyTransferMode.BOTH;
|
||||
public class EnergyManager extends EnergyStorage implements IStreamable, INbtReadable, INbtWritable {
|
||||
@Nonnull
|
||||
private EnergyTransferMode externalMode = EnergyTransferMode.BOTH;
|
||||
|
||||
public EnergyManager(int maxTransfer, int capacity) {
|
||||
this.energyStorage = new EnergyStorage(scaleForDifficulty(capacity), scaleForDifficulty(maxTransfer), scaleForDifficulty(maxTransfer));
|
||||
super(EnergyHelper.scaleForDifficulty(capacity), EnergyHelper.scaleForDifficulty(maxTransfer), EnergyHelper.scaleForDifficulty(maxTransfer));
|
||||
}
|
||||
|
||||
public static int scaleForDifficulty(int energyPerUse) {
|
||||
return Math.round(energyPerUse * ForestryAPI.activeMode.getFloatSetting("energy.demand.modifier"));
|
||||
public void setExternalMode(@Nonnull EnergyTransferMode externalMode) {
|
||||
this.externalMode = externalMode;
|
||||
}
|
||||
|
||||
public void setExtractOnly() {
|
||||
mode = EnergyTransferMode.EXTRACT;
|
||||
@Nonnull
|
||||
public EnergyTransferMode getExternalMode() {
|
||||
return externalMode;
|
||||
}
|
||||
|
||||
public void setReceiveOnly() {
|
||||
mode = EnergyTransferMode.RECEIVE;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private boolean canExtract() {
|
||||
switch (mode) {
|
||||
case EXTRACT:
|
||||
case BOTH:
|
||||
return true;
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
final int energy;
|
||||
if (nbt.hasKey("EnergyManager")) { // legacy
|
||||
NBTTagCompound energyManagerNBT = nbt.getCompoundTag("EnergyManager");
|
||||
NBTTagCompound energyStorageNBT = energyManagerNBT.getCompoundTag("EnergyStorage");
|
||||
energy = energyStorageNBT.getInteger("Energy");
|
||||
} else {
|
||||
energy = nbt.getInteger("Energy");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private boolean canReceive() {
|
||||
switch (mode) {
|
||||
case RECEIVE:
|
||||
case BOTH:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
public EnergyManager readFromNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound energyManagerNBT = nbt.getCompoundTag("EnergyManager");
|
||||
NBTTagCompound energyStorageNBT = energyManagerNBT.getCompoundTag("EnergyStorage");
|
||||
energyStorage.readFromNBT(energyStorageNBT);
|
||||
|
||||
return this;
|
||||
|
||||
setEnergyStored(energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound energyStorageNBT = new NBTTagCompound();
|
||||
energyStorage.writeToNBT(energyStorageNBT);
|
||||
|
||||
NBTTagCompound energyManagerNBT = new NBTTagCompound();
|
||||
energyManagerNBT.setTag("EnergyStorage", energyStorageNBT);
|
||||
nbt.setTag("EnergyManager", energyManagerNBT);
|
||||
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
int energyStored = energyStorage.getEnergyStored();
|
||||
data.writeInt(energyStored);
|
||||
data.writeVarInt(this.energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
int energyStored = data.readInt();
|
||||
energyStorage.setEnergyStored(energyStored);
|
||||
}
|
||||
|
||||
public int toGuiInt() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
public void fromGuiInt(int packetInt) {
|
||||
energyStorage.setEnergyStored(packetInt);
|
||||
}
|
||||
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
if (!canReceive()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
|
||||
if (!canExtract()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
public int getTotalEnergyStored() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return energyStorage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return energyStorage.getMaxEnergyStored();
|
||||
int energyStored = data.readVarInt();
|
||||
setEnergyStored(energyStored);
|
||||
}
|
||||
|
||||
public int getMaxEnergyReceived() {
|
||||
return energyStorage.getMaxReceive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes one work cycle's worth of energy.
|
||||
*
|
||||
* @return true if the energy to do work was consumed
|
||||
*/
|
||||
public boolean consumeEnergyToDoWork(int ticksPerWorkCycle, int energyPerWorkCycle) {
|
||||
int energyPerCycle = (int) Math.ceil(energyPerWorkCycle / (float) ticksPerWorkCycle);
|
||||
if (energyStorage.getEnergyStored() < energyPerCycle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
energyStorage.modifyEnergyStored(-energyPerCycle);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this can send energy to the target tile
|
||||
*/
|
||||
public boolean canSendEnergy(EnumFacing orientation, TileEntity tile) {
|
||||
return sendEnergy(orientation, tile, Integer.MAX_VALUE, true) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends as much energy as it can to the tile at orientation.
|
||||
* For power sources. Ignores canExtract()
|
||||
*
|
||||
* @return amount sent
|
||||
*/
|
||||
public int sendEnergy(EnumFacing orientation, TileEntity tile) {
|
||||
return sendEnergy(orientation, tile, Integer.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends amount of energy to the tile at orientation.
|
||||
* For power sources. Ignores canExtract()
|
||||
*
|
||||
* @return amount sent
|
||||
*/
|
||||
public int sendEnergy(EnumFacing orientation, TileEntity tile, int amount, boolean simulate) {
|
||||
int sent = 0;
|
||||
if (tile != null) {
|
||||
int extractable = energyStorage.extractEnergy(amount, true);
|
||||
if (extractable > 0) {
|
||||
EnumFacing side = orientation.getOpposite();
|
||||
if (TESLA_CONSUMER != null && tile.hasCapability(TESLA_CONSUMER, side)) {
|
||||
sent = sendEnergyTesla(tile, side, extractable, simulate);
|
||||
} else if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver receptor = (IEnergyReceiver) tile;
|
||||
sent = receptor.receiveEnergy(side, extractable, simulate);
|
||||
} else if (tile instanceof TileEngine) { // engine chaining
|
||||
TileEngine receptor = (TileEngine) tile;
|
||||
sent = receptor.getEnergyManager().receiveEnergy(side, extractable, simulate);
|
||||
}
|
||||
|
||||
energyStorage.extractEnergy(sent, simulate);
|
||||
}
|
||||
}
|
||||
return sent;
|
||||
return this.maxReceive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains an amount of energy, due to decay from lack of work or other factors
|
||||
*/
|
||||
public void drainEnergy(int amount) {
|
||||
energyStorage.modifyEnergyStored(-amount);
|
||||
setEnergyStored(energy - amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an amount of energy, generated by engines
|
||||
*/
|
||||
public void generateEnergy(int amount) {
|
||||
energyStorage.modifyEnergyStored(amount);
|
||||
setEnergyStored(energy + amount);
|
||||
}
|
||||
|
||||
public void setEnergyStored(int energyStored) {
|
||||
this.energy = energyStored;
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCapability(Capability<?> capability) {
|
||||
if (capability == TESLA_PRODUCER && canExtract()) {
|
||||
return true;
|
||||
} else if (capability == TESLA_CONSUMER && canReceive()) {
|
||||
return true;
|
||||
} else if (capability == TESLA_HOLDER) {
|
||||
return true;
|
||||
if (capability == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (capability == CapabilityEnergy.ENERGY) {
|
||||
return true;
|
||||
} else if (capability == TeslaHelper.TESLA_PRODUCER && externalMode.canExtract()) {
|
||||
return true;
|
||||
} else if (capability == TeslaHelper.TESLA_CONSUMER && externalMode.canReceive()) {
|
||||
return true;
|
||||
} else if (capability == TeslaHelper.TESLA_HOLDER) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability) {
|
||||
if (capability == TESLA_PRODUCER && canExtract()) {
|
||||
return TESLA_PRODUCER.cast(this);
|
||||
} else if (capability == TESLA_CONSUMER && canReceive()) {
|
||||
return TESLA_CONSUMER.cast(this);
|
||||
} else if (capability == TESLA_HOLDER) {
|
||||
return TESLA_HOLDER.cast(this);
|
||||
if (capability == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = Constants.TESLA_MOD_ID)
|
||||
public static int sendEnergyTesla(TileEntity tile, EnumFacing side, int amount, boolean simulate) {
|
||||
ITeslaConsumer consumer = tile.getCapability(TESLA_CONSUMER, side);
|
||||
return (int) consumer.givePower(amount, simulate);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = Constants.TESLA_MOD_ID)
|
||||
@Override
|
||||
public long givePower(long power, boolean simulated) {
|
||||
if (!canReceive()) {
|
||||
return 0;
|
||||
if (capability == CapabilityEnergy.ENERGY) {
|
||||
IEnergyStorage energyStorage = new EnergyStorageWrapper(this, externalMode);
|
||||
return CapabilityEnergy.ENERGY.cast(energyStorage);
|
||||
} else if (capability == TeslaHelper.TESLA_PRODUCER && externalMode.canExtract()) {
|
||||
return TeslaHelper.TESLA_PRODUCER.cast(new TeslaProducerWrapper(this));
|
||||
} else if (capability == TeslaHelper.TESLA_CONSUMER && externalMode.canReceive()) {
|
||||
return TeslaHelper.TESLA_CONSUMER.cast(new TeslaConsumerWrapper(this));
|
||||
} else if (capability == TeslaHelper.TESLA_HOLDER) {
|
||||
return TeslaHelper.TESLA_HOLDER.cast(new TeslaHolderWrapper(this));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return energyStorage.receiveEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = Constants.TESLA_MOD_ID)
|
||||
@Override
|
||||
public long takePower(long power, boolean simulated) {
|
||||
if (!canExtract()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.extractEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = Constants.TESLA_MOD_ID)
|
||||
@Override
|
||||
public long getStoredPower() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Optional.Method(modid = Constants.TESLA_MOD_ID)
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return energyStorage.getMaxEnergyStored();
|
||||
}
|
||||
}
|
||||
Loaded 100 of 172 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user