mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 17:44:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
523a8da908 | ||
|
|
cd10500a17 | ||
|
|
6d9211ada1 | ||
|
|
003ca9273d | ||
|
|
28f65f13a5 | ||
|
|
21ee0947d7 | ||
|
|
1e11992de2 | ||
|
|
d690a38fa2 | ||
|
|
46eb29cf28 | ||
|
|
fb01d3ffaa | ||
|
|
e676a73a7c | ||
|
|
6e348dbc5d | ||
|
|
39114ec429 | ||
|
|
3b82fe3bd0 | ||
|
|
2667334252 | ||
|
|
be39e2c3c3 |
No files matched your search
@@ -55,6 +55,9 @@ sourceSets {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'http://maven.epoxide.xyz'
|
||||
}
|
||||
maven {
|
||||
url "http://dvs1.progwml6.com/files/maven"
|
||||
}
|
||||
@@ -65,6 +68,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
deobfCompile "net.darkhax.tesla:Tesla:${tesla_version}"
|
||||
deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}:api"
|
||||
runtime "mezz.jei:jei_${mcversion}:${jei_version}"
|
||||
deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
|
||||
|
||||
+6
-5
@@ -1,10 +1,11 @@
|
||||
mcversion=1.10
|
||||
forgeversion=12.18.0.1989-1.10.0
|
||||
mcversion=1.10.2
|
||||
forgeversion=12.18.0.2005-1.10.0
|
||||
mcp_mappings=snapshot_20160525
|
||||
|
||||
jei_version=3.7.0.+
|
||||
ic2_version=2.5.5-ex19
|
||||
tesla_version=1.9.4-1.1.0.24
|
||||
jei_version=3.7.3.221
|
||||
ic2_version=2.6.5-ex110
|
||||
|
||||
version_major=5
|
||||
version_minor=1
|
||||
version_patch=7
|
||||
version_patch=11
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#Tue Jun 21 15:23:47 PDT 2016
|
||||
#Mon Sep 14 12:28:28 PDT 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
|
||||
+1
-1
Submodule lang updated: 2d88011e4a...82c5455d7b.
@@ -12,6 +12,7 @@ package forestry;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -51,7 +52,8 @@ import forestry.plugins.PluginManager;
|
||||
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
|
||||
acceptedMinecraftVersions = "[1.10]",
|
||||
dependencies = "required-after:Forge@[12.18.0.1989,);"
|
||||
+ "after:JEI@[3.7.0,);")
|
||||
+ "after:JEI@[3.7.0,);"
|
||||
+ "after:" + PluginIC2.modId + ";")
|
||||
public class Forestry {
|
||||
|
||||
@Mod.Instance(Constants.MOD_ID)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
@@ -32,6 +34,7 @@ public interface IBeeHousing extends IHousing, IErrorLogicSource {
|
||||
*/
|
||||
Iterable<IBeeListener> getBeeListeners();
|
||||
|
||||
@Nonnull
|
||||
IBeeHousingInventory getBeeInventory();
|
||||
|
||||
IBeekeepingLogic getBeekeepingLogic();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -233,7 +234,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
if (beeType == EnumBeeType.PRINCESS) {
|
||||
tickBreed();
|
||||
} else if (beeType == EnumBeeType.QUEEN) {
|
||||
queenWorkTick(queen);
|
||||
queenWorkTick(queen, queenStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +247,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
}
|
||||
}
|
||||
|
||||
private void queenWorkTick(IBee queen) {
|
||||
private void queenWorkTick(@Nullable IBee queen, @Nonnull ItemStack queenStack) {
|
||||
if (queen == null) {
|
||||
beeProgress = 0;
|
||||
beeProgressMax = 0;
|
||||
@@ -272,7 +273,8 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
// Write the changed queen back into the item stack.
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
queen.writeToNBT(nbttagcompound);
|
||||
housing.getBeeInventory().getQueen().setTagCompound(nbttagcompound);
|
||||
queenStack.setTagCompound(nbttagcompound);
|
||||
housing.getBeeInventory().setQueen(queenStack);
|
||||
}
|
||||
|
||||
beeProgress = queen.getHealth();
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.util.EnumFacing;
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.apiculture.IBeeHousingInventory;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
@@ -27,8 +26,8 @@ public class InventoryBeeHousing extends InventoryAdapterRestricted implements I
|
||||
public static final int SLOT_PRODUCT_1 = 2;
|
||||
public static final int SLOT_PRODUCT_COUNT = 7;
|
||||
|
||||
public InventoryBeeHousing(int size, IAccessHandler accessHandler) {
|
||||
super(size, "Items", accessHandler);
|
||||
public InventoryBeeHousing(int size) {
|
||||
super(size, "Items");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.entities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -36,9 +37,12 @@ import forestry.core.config.Config;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
|
||||
public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implements IApiary {
|
||||
@Nonnull
|
||||
private static final IBeeModifier beeModifier = new ApiaryBeeModifier();
|
||||
@Nonnull
|
||||
private final IBeeListener beeListener = new ApiaryBeeListener(this);
|
||||
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
|
||||
@Nonnull
|
||||
private final InventoryApiary inventory = new InventoryApiary();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public EntityMinecartApiary(World world) {
|
||||
@@ -64,6 +68,7 @@ public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implement
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -10,17 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.entities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
@@ -36,10 +31,24 @@ import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.owner.GameProfileDataSerializer;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IOwnedTile, IGuiBeeHousingInventory, IClimatised, IStreamableGui {
|
||||
private static final DataParameter<Optional<GameProfile>> OWNER = EntityDataManager.createKey(EntityMinecart.class, GameProfileDataSerializer.INSTANCE);
|
||||
|
||||
public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IGuiBeeHousingInventory, IClimatised, IStreamableGui {
|
||||
private static final Random random = new Random();
|
||||
private static final int beeFXInterval = 4;
|
||||
private static final int pollenFXInterval = 50;
|
||||
@@ -49,6 +58,23 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
|
||||
private final IBeekeepingLogic beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
|
||||
private final IErrorLogic errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
|
||||
private final OwnerHandler ownerHandler = new OwnerHandler() {
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
super.setOwner(owner);
|
||||
dataManager.set(OWNER, Optional.of(owner));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
Optional<GameProfile> gameProfileOptional = dataManager.get(OWNER);
|
||||
if (gameProfileOptional.isPresent()) {
|
||||
return gameProfileOptional.get();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// CLIENT
|
||||
private int breedingProgressPercent = 0;
|
||||
@@ -63,6 +89,18 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
super(world, posX, posY, posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit();
|
||||
this.dataManager.register(OWNER, Optional.absent());
|
||||
}
|
||||
|
||||
/* IOwnedTile */
|
||||
@Override
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return ownerHandler;
|
||||
}
|
||||
|
||||
/* IBeeHousing */
|
||||
@Override
|
||||
public IBeekeepingLogic getBeekeepingLogic() {
|
||||
@@ -111,7 +149,7 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return getAccessHandler().getOwner();
|
||||
return getOwnerHandler().getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,11 +212,13 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
super.readEntityFromNBT(nbtTagCompound);
|
||||
beeLogic.readFromNBT(nbtTagCompound);
|
||||
ownerHandler.readFromNBT(nbtTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {
|
||||
super.writeEntityToNBT(nbtTagCompound);
|
||||
beeLogic.writeToNBT(nbtTagCompound);
|
||||
ownerHandler.writeToNBT(nbtTagCompound);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.entities;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,7 +34,7 @@ import forestry.core.inventory.IInventoryAdapter;
|
||||
public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase {
|
||||
private static final IBeeModifier beeModifier = new BeehouseBeeModifier();
|
||||
private static final IBeeListener beeListener = new DefaultBeeListener();
|
||||
private final InventoryBeeHousing beeInventory = new InventoryBeeHousing(9, getAccessHandler());
|
||||
private final InventoryBeeHousing beeInventory = new InventoryBeeHousing(9);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public EntityMinecartBeehouse(World world) {
|
||||
@@ -72,6 +73,7 @@ public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase {
|
||||
return Collections.singleton(beeListener);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return beeInventory;
|
||||
|
||||
@@ -22,15 +22,14 @@ import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeekeepingMode;
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import forestry.apiculture.InventoryBeeHousing;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
|
||||
public class InventoryApiary extends InventoryBeeHousing implements IApiaryInventory {
|
||||
public static final int SLOT_FRAMES_1 = 9;
|
||||
public static final int SLOT_FRAMES_COUNT = 3;
|
||||
|
||||
public InventoryApiary(IAccessHandler accessHandler) {
|
||||
super(12, accessHandler);
|
||||
public InventoryApiary() {
|
||||
super(12);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -66,7 +66,8 @@ public class ItemMinecartBeehouse extends ItemMinecart implements IItemModelRegi
|
||||
} else {
|
||||
entityMinecart = new EntityMinecartApiary(worldIn, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F);
|
||||
}
|
||||
entityMinecart.setOwner(playerIn.getGameProfile());
|
||||
|
||||
entityMinecart.getOwnerHandler().setOwner(playerIn.getGameProfile());
|
||||
|
||||
if (stack.hasDisplayName()) {
|
||||
entityMinecart.setCustomNameTag(stack.getDisplayName());
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
@@ -39,7 +38,6 @@ import forestry.api.multiblock.IAlvearyComponent;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.apiculture.AlvearyBeeModifier;
|
||||
import forestry.apiculture.InventoryBeeHousing;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
@@ -53,6 +51,7 @@ import forestry.core.utils.Translator;
|
||||
|
||||
public class AlvearyController extends RectangularMultiblockControllerBase implements IAlvearyControllerInternal, IClimateControlled {
|
||||
|
||||
@Nonnull
|
||||
private final InventoryBeeHousing inventory;
|
||||
private final IBeekeepingLogic beekeepingLogic;
|
||||
|
||||
@@ -71,12 +70,13 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
|
||||
|
||||
public AlvearyController(World world) {
|
||||
super(world, AlvearyMultiblockSizeLimits.instance);
|
||||
this.inventory = new InventoryBeeHousing(9, getAccessHandler());
|
||||
this.inventory = new InventoryBeeHousing(9);
|
||||
this.beekeepingLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
|
||||
|
||||
this.beeModifiers.add(new AlvearyBeeModifier());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return inventory;
|
||||
@@ -340,20 +340,6 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
|
||||
return new Vec3d(coord.getX() + 0.5, coord.getY() + 1.5, coord.getZ() + 0.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
|
||||
// pipes connected to this need to update
|
||||
for (IMultiblockComponent part : connectedParts) {
|
||||
if (part instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity) part;
|
||||
worldObj.notifyBlockOfStateChange(tile.getPos(), tile.getBlockType());
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
BlockPos coords = getReferenceCoord();
|
||||
@@ -383,7 +369,7 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return getAccessHandler().getOwner();
|
||||
return getOwnerHandler().getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -45,6 +46,7 @@ public class FakeAlvearyController extends FakeMultiblockController implements I
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return FakeBeeHousingInventory.instance;
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
package forestry.apiculture.multiblock;
|
||||
|
||||
import forestry.api.multiblock.IAlvearyController;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
|
||||
public interface IAlvearyControllerInternal extends IAlvearyController, IMultiblockControllerInternal, IClimatised, IRestrictedAccess, IStreamableGui {
|
||||
public interface IAlvearyControllerInternal extends IAlvearyController, IMultiblockControllerInternal, IClimatised, IOwnedTile, IStreamableGui {
|
||||
IInventoryAdapter getInternalInventory();
|
||||
|
||||
int getHealthScaled(int i);
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -33,9 +36,6 @@ import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.apiculture.blocks.BlockAlvearyType;
|
||||
import forestry.apiculture.gui.ContainerAlveary;
|
||||
import forestry.apiculture.gui.GuiAlveary;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.IHintSource;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
@@ -46,7 +46,7 @@ import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.core.tiles.ITitled;
|
||||
|
||||
public abstract class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent, IRestrictedAccess, IStreamableGui, ITitled, IClimatised, IHintSource {
|
||||
public abstract class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimatised, IHintSource {
|
||||
private final String unlocalizedTitle;
|
||||
|
||||
protected TileAlveary() {
|
||||
@@ -99,6 +99,7 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry<Multibloc
|
||||
return getMultiblockLogic().getController().getBeeListeners();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return getMultiblockLogic().getController().getBeeInventory();
|
||||
@@ -141,13 +142,8 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry<Multibloc
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return getMultiblockLogic().getController().getAccessHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess);
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return getMultiblockLogic().getController().getOwnerHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.apiculture.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -23,6 +24,7 @@ import forestry.core.tiles.IActivatable;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiver, IActivatable, IAlvearyComponent.Climatiser {
|
||||
|
||||
@@ -143,4 +145,18 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package forestry.apiculture.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousingInventory;
|
||||
|
||||
public class FakeBeeHousingInventory implements IBeeHousingInventory {
|
||||
@Nonnull
|
||||
public static final FakeBeeHousingInventory instance = new FakeBeeHousingInventory();
|
||||
|
||||
private FakeBeeHousingInventory() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -30,15 +31,19 @@ import forestry.apiculture.inventory.IApiaryInventory;
|
||||
import forestry.apiculture.inventory.InventoryApiary;
|
||||
|
||||
public class TileApiary extends TileBeeHousingBase implements IApiary {
|
||||
@Nonnull
|
||||
private final IBeeModifier beeModifier = new ApiaryBeeModifier();
|
||||
@Nonnull
|
||||
private final IBeeListener beeListener = new ApiaryBeeListener(this);
|
||||
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
|
||||
@Nonnull
|
||||
private final InventoryApiary inventory = new InventoryApiary();
|
||||
|
||||
public TileApiary() {
|
||||
super("apiary");
|
||||
setInternalInventory(inventory);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -24,20 +25,24 @@ import forestry.apiculture.gui.ContainerBeeHousing;
|
||||
import forestry.apiculture.gui.GuiBeeHousing;
|
||||
|
||||
public class TileBeeHouse extends TileBeeHousingBase {
|
||||
@Nonnull
|
||||
private static final IBeeModifier beeModifier = new BeehouseBeeModifier();
|
||||
|
||||
@Nonnull
|
||||
private final IBeeListener beeListener;
|
||||
@Nonnull
|
||||
private final InventoryBeeHousing beeInventory;
|
||||
|
||||
public TileBeeHouse() {
|
||||
super("bee.house");
|
||||
this.beeListener = new DefaultBeeListener();
|
||||
|
||||
beeInventory = new InventoryBeeHousing(12, getAccessHandler());
|
||||
beeInventory = new InventoryBeeHousing(12);
|
||||
beeInventory.disableAutomation();
|
||||
setInternalInventory(beeInventory);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return beeInventory;
|
||||
|
||||
@@ -13,13 +13,7 @@ package forestry.apiculture.tiles;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
@@ -30,11 +24,19 @@ import forestry.apiculture.gui.IGuiBeeHousingInventory;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.core.tiles.TileBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IClimatised, IGuiBeeHousingInventory, IStreamableGui {
|
||||
public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IOwnedTile, IClimatised, IGuiBeeHousingInventory, IStreamableGui {
|
||||
private final OwnerHandler ownerHandler = new OwnerHandler();
|
||||
private final IBeekeepingLogic beeLogic;
|
||||
private Biome cachedBiome;
|
||||
|
||||
@@ -57,6 +59,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
beeLogic.writeToNBT(nbttagcompound);
|
||||
ownerHandler.writeToNBT(nbttagcompound);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@@ -64,6 +67,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
beeLogic.readFromNBT(nbttagcompound);
|
||||
ownerHandler.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -71,6 +75,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
NBTTagCompound updateTag = super.getUpdateTag();
|
||||
beeLogic.writeToNBT(updateTag);
|
||||
ownerHandler.writeToNBT(updateTag);
|
||||
return updateTag;
|
||||
}
|
||||
|
||||
@@ -78,6 +83,12 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
|
||||
super.handleUpdateTag(tag);
|
||||
beeLogic.readFromNBT(tag);
|
||||
ownerHandler.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return ownerHandler;
|
||||
}
|
||||
|
||||
/* ICLIMATISED */
|
||||
@@ -171,7 +182,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return getAccessHandler().getOwner();
|
||||
return getOwnerHandler().getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,26 +15,8 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
@@ -62,9 +44,41 @@ import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.utils.DamageSourceForestry;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
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.IMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
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");
|
||||
@@ -113,7 +127,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);
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox, BEE_TARGET_PREDICATE);
|
||||
if (!entities.isEmpty()) {
|
||||
Collections.shuffle(entities);
|
||||
EntityLivingBase entity = entities.get(0);
|
||||
@@ -293,6 +307,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBeeHousingInventory getBeeInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -101,7 +101,6 @@ public class BlockArbDoor extends BlockDoor implements IWoodTyped, IItemModelReg
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
|
||||
return new ItemStack(getItem());
|
||||
}
|
||||
|
||||
@@ -1010,7 +1010,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
|
||||
return false;
|
||||
}
|
||||
|
||||
tileLeaves.setOwner(owner);
|
||||
tileLeaves.getOwnerHandler().setOwner(owner);
|
||||
tileLeaves.setTree(new Tree(genome));
|
||||
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
|
||||
@@ -219,15 +219,14 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileSapling)) {
|
||||
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (sapling == null) {
|
||||
world.setBlockToAir(pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
TileSapling sapling = (TileSapling) tile;
|
||||
sapling.setTree(tree.copy());
|
||||
sapling.setOwner(owner);
|
||||
sapling.getOwnerHandler().setOwner(owner);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
|
||||
@@ -13,7 +13,6 @@ import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.blocks.BlockPile;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.multiblock.MultiblockRegistry;
|
||||
import forestry.core.multiblock.MultiblockValidationException;
|
||||
@@ -307,10 +306,6 @@ public class CharcoalPileController extends RectangularMultiblockControllerBase
|
||||
active = data.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return null;
|
||||
|
||||
@@ -461,7 +461,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
|
||||
|
||||
if (maturationTime >= caterpillarMatureTime) {
|
||||
ButterflyManager.butterflyRoot.plantCocoon(worldObj, this, getOwner(), 0);
|
||||
ButterflyManager.butterflyRoot.plantCocoon(worldObj, this, getOwnerHandler().getOwner(), 0);
|
||||
setCaterpillar(null);
|
||||
} else if (!wasDestroyed && isDestroyed(tree, damage)) {
|
||||
sendNetworkUpdate();
|
||||
|
||||
@@ -106,7 +106,7 @@ public class TileSapling extends TileTreeContainer {
|
||||
}
|
||||
|
||||
if (generated) {
|
||||
IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(worldObj, getOwner());
|
||||
IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(worldObj, getOwnerHandler().getOwner());
|
||||
breedingTracker.registerBirth(tree);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,19 @@ import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.genetics.Tree;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.utils.NBTUtilForestry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
@@ -25,30 +35,16 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.genetics.Tree;
|
||||
import forestry.core.access.IOwnable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.utils.NBTUtilForestry;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
|
||||
/**
|
||||
* This is the base TE class for any block that needs to contain tree genome information.
|
||||
*
|
||||
* @author SirSengir
|
||||
*/
|
||||
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnable {
|
||||
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnedTile {
|
||||
|
||||
@Nullable
|
||||
private ITree containedTree;
|
||||
@Nullable
|
||||
private GameProfile owner;
|
||||
private final OwnerHandler ownerHandler = new OwnerHandler();
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
@@ -58,9 +54,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
|
||||
if (nbttagcompound.hasKey("ContainedTree")) {
|
||||
containedTree = new Tree(nbttagcompound.getCompoundTag("ContainedTree"));
|
||||
}
|
||||
if (nbttagcompound.hasKey("owner")) {
|
||||
owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"));
|
||||
}
|
||||
ownerHandler.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -73,11 +67,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
|
||||
containedTree.writeToNBT(subcompound);
|
||||
nbttagcompound.setTag("ContainedTree", subcompound);
|
||||
}
|
||||
if (this.owner != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
PlayerUtil.writeGameProfile(nbt, owner);
|
||||
nbttagcompound.setTag("owner", nbt);
|
||||
}
|
||||
ownerHandler.writeToNBT(nbttagcompound);
|
||||
|
||||
return nbttagcompound;
|
||||
}
|
||||
@@ -122,26 +112,9 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
|
||||
return this.containedTree;
|
||||
}
|
||||
|
||||
/* IOwnable */
|
||||
@Nullable
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(EntityPlayer player) {
|
||||
return player != null && PlayerUtil.isSameGameProfile(player.getGameProfile(), owner);
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return ownerHandler;
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
return tile.getOwner();
|
||||
return tile.getOwnerHandler().getOwner();
|
||||
}
|
||||
|
||||
public void preGenerate(World world, Random rand, BlockPos startPos) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.owner.GameProfileDataSerializer;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -119,6 +120,8 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
public void preInit() {
|
||||
super.preInit();
|
||||
|
||||
GameProfileDataSerializer.register();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
rootCommand.addChildCommand(new CommandPlugins());
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.packets.PacketAccessSwitch;
|
||||
import forestry.core.network.packets.PacketAccessSwitchEntity;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
|
||||
public final class AccessHandler implements IAccessHandler {
|
||||
private final IRestrictedAccess accessListener;
|
||||
private final List<IAccessOwnerListener> accessOwnerListeners = new ArrayList<>();
|
||||
private final Object target;
|
||||
|
||||
private GameProfile owner = null;
|
||||
private EnumAccess access = EnumAccess.SHARED;
|
||||
|
||||
public <T extends IRestrictedAccess & ILocatable> AccessHandler(T tile) {
|
||||
this.accessListener = tile;
|
||||
this.target = tile;
|
||||
}
|
||||
|
||||
public <T extends Entity & IRestrictedAccess> AccessHandler(T entity) {
|
||||
this.accessListener = entity;
|
||||
this.target = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOwnerListener(IAccessOwnerListener accessListener) {
|
||||
accessOwnerListeners.add(accessListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeOwnerListener(IAccessOwnerListener accessListener) {
|
||||
accessOwnerListeners.remove(accessListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean allowsRemoval(EntityPlayer player) {
|
||||
return !Config.enablePermissions || getAccess() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean allowsAlteration(EntityPlayer player) {
|
||||
return allowsRemoval(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean allowsViewing(EntityPlayer player) {
|
||||
return allowsAlteration(player) || getAccess() == EnumAccess.VIEWABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsInteracting(EntityPlayer player) {
|
||||
return allowsAlteration(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean allowsPipeConnections() {
|
||||
return access == EnumAccess.SHARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAccess getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
for (IAccessOwnerListener listener : accessOwnerListeners) {
|
||||
listener.onOwnerSet(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(EntityPlayer player) {
|
||||
return PlayerUtil.isSameGameProfile(owner, player.getGameProfile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchAccess(EntityPlayer player) {
|
||||
if (!isOwner(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ordinal = (access.ordinal() + 1) % EnumAccess.values().length;
|
||||
EnumAccess newAccess = EnumAccess.values()[ordinal];
|
||||
setAccess(player.worldObj, newAccess);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setAccess(World world, EnumAccess access) {
|
||||
EnumAccess oldAccess = this.access;
|
||||
if (oldAccess == access) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.access = access;
|
||||
|
||||
if (world.isRemote) {
|
||||
if (target instanceof ILocatable) {
|
||||
Proxies.net.sendToServer(new PacketAccessSwitch((ILocatable) target));
|
||||
} else if (target instanceof Entity) {
|
||||
Proxies.net.sendToServer(new PacketAccessSwitchEntity((Entity) target));
|
||||
}
|
||||
} else {
|
||||
accessListener.onSwitchAccess(oldAccess, access);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
if (owner == null) {
|
||||
data.writeByte(-1);
|
||||
} else {
|
||||
data.writeByte(access.ordinal());
|
||||
data.writeLong(owner.getId().getMostSignificantBits());
|
||||
data.writeLong(owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(owner.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
byte accessOrdinal = data.readByte();
|
||||
if (accessOrdinal >= 0) {
|
||||
access = EnumAccess.values()[accessOrdinal];
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
setOwner(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
access = EnumAccess.values()[data.getInteger("Access")];
|
||||
|
||||
if (data.hasKey("owner")) {
|
||||
owner = PlayerUtil.readGameProfileFromNBT(data.getCompoundTag("owner"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
data.setInteger("Access", access.ordinal());
|
||||
|
||||
if (this.owner != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
PlayerUtil.writeGameProfile(nbt, owner);
|
||||
data.setTag("owner", nbt);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public enum EnumAccess {
|
||||
SHARED("for.gui.rule.shared"), VIEWABLE("for.gui.rule.restricted"), PRIVATE("for.gui.rule.private");
|
||||
|
||||
private final String unlocalizedName;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private TextureAtlasSprite icon;
|
||||
|
||||
EnumAccess(String unlocalizedName) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return this.unlocalizedName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
|
||||
public class FakeAccessHandler implements IAccessHandler {
|
||||
private static FakeAccessHandler instance;
|
||||
|
||||
public static FakeAccessHandler getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new FakeAccessHandler();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private FakeAccessHandler() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchAccess(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAccess getAccess() {
|
||||
return EnumAccess.SHARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsRemoval(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsAlteration(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsViewing(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsInteracting(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsPipeConnections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOwnerListener(IAccessOwnerListener accessListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeOwnerListener(IAccessOwnerListener accessListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.IStreamable;
|
||||
|
||||
public interface IAccessHandler extends IOwnable, IStreamable, INbtWritable, INbtReadable {
|
||||
|
||||
boolean switchAccess(EntityPlayer player);
|
||||
|
||||
EnumAccess getAccess();
|
||||
|
||||
boolean allowsRemoval(EntityPlayer player);
|
||||
|
||||
boolean allowsAlteration(EntityPlayer player);
|
||||
|
||||
boolean allowsViewing(EntityPlayer player);
|
||||
|
||||
boolean allowsInteracting(EntityPlayer player);
|
||||
|
||||
boolean allowsPipeConnections();
|
||||
|
||||
void addOwnerListener(IAccessOwnerListener accessListener);
|
||||
|
||||
void removeOwnerListener(IAccessOwnerListener accessListener);
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
public interface IRestrictedAccess {
|
||||
IAccessHandler getAccessHandler();
|
||||
|
||||
void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess);
|
||||
}
|
||||
@@ -36,7 +36,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
@@ -50,7 +49,6 @@ import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.ISpriteRegister;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.ITextureManager;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.MachineParticleCallback;
|
||||
@@ -60,7 +58,6 @@ import forestry.core.tiles.TileBase;
|
||||
import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister {
|
||||
/** use this instead of {@link BlockHorizontal#FACING} so the blocks rotate in a circle instead of NSWE order. */
|
||||
@@ -148,35 +145,25 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
TileBase tile = TileUtil.getTile(worldIn, pos, TileBase.class);
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
if (tile != null) {
|
||||
if (TileUtil.isUsableByPlayer(playerIn, tile)) {
|
||||
|
||||
if (!TileUtil.isUsableByPlayer(playerIn, tile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IAccessHandler access = tile.getAccessHandler();
|
||||
|
||||
if (!playerIn.isSneaking()) {
|
||||
if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
||||
IFluidHandler tileFluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
||||
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, playerIn)) {
|
||||
return true;
|
||||
if (!playerIn.isSneaking()) {
|
||||
if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
||||
IFluidHandler tileFluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
||||
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, playerIn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldIn.isRemote) {
|
||||
tile.openGui(playerIn, heldItem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (worldIn.isRemote) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (access.allowsViewing(playerIn)) {
|
||||
tile.openGui(playerIn, heldItem);
|
||||
} else {
|
||||
playerIn.addChatMessage(new TextComponentTranslation("for.chat.accesslocked", PlayerUtil.getOwnerName(access)));
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.blocks;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -25,8 +27,6 @@ import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.access.IOwnable;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
@@ -38,20 +38,6 @@ public abstract class BlockForestry extends Block implements IItemModelRegister,
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
|
||||
if (!restrictedAccessTile.getAccessHandler().allowsRemoval(player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.removedByPlayer(state, world, pos, player, willHarvest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
if (world.isRemote) {
|
||||
@@ -61,19 +47,12 @@ public abstract class BlockForestry extends Block implements IItemModelRegister,
|
||||
if (placer instanceof EntityPlayer) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
IOwnable ownable;
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
ownable = ((IRestrictedAccess) tile).getAccessHandler();
|
||||
} else if (tile instanceof IOwnable) {
|
||||
ownable = (IOwnable) tile;
|
||||
} else {
|
||||
return;
|
||||
if (tile instanceof IOwnedTile) {
|
||||
IOwnerHandler ownerHandler = ((IOwnedTile) tile).getOwnerHandler();
|
||||
EntityPlayer player = (EntityPlayer) placer;
|
||||
GameProfile gameProfile = player.getGameProfile();
|
||||
ownerHandler.setOwner(gameProfile);
|
||||
}
|
||||
|
||||
EntityPlayer player = (EntityPlayer) placer;
|
||||
GameProfile gameProfile = player.getGameProfile();
|
||||
ownable.setOwner(gameProfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,33 +10,23 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.entities;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
|
||||
|
||||
import forestry.core.access.AccessHandler;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.gui.IGuiHandlerEntity;
|
||||
import forestry.core.gui.IHintSource;
|
||||
import forestry.core.tiles.ITitled;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
|
||||
|
||||
public abstract class EntityMinecartForestry extends EntityMinecart implements ITitled, IRestrictedAccess, IHintSource, IGuiHandlerEntity {
|
||||
private final AccessHandler accessHandler = new AccessHandler(this);
|
||||
public abstract class EntityMinecartForestry extends EntityMinecart implements ITitled, IHintSource, IGuiHandlerEntity {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public EntityMinecartForestry(World world) {
|
||||
@@ -61,27 +51,11 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setOwner(GameProfile owner) {
|
||||
accessHandler.setOwner(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
super.readEntityFromNBT(nbtTagCompound);
|
||||
accessHandler.readFromNBT(nbtTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {
|
||||
super.writeEntityToNBT(nbtTagCompound);
|
||||
accessHandler.writeToNBT(nbtTagCompound);
|
||||
}
|
||||
|
||||
/* EntityMinecart */
|
||||
@Override
|
||||
public boolean canBeRidden() {
|
||||
@@ -127,17 +101,6 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
|
||||
ItemStack cartItem = getCartItem();
|
||||
return cartItem.getUnlocalizedName() + ".name";
|
||||
}
|
||||
|
||||
/* IRestrictedAccess */
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return accessHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdOfEntity() {
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuil
|
||||
|
||||
@Override
|
||||
public ItemStack[] getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
|
||||
if (world.rand.nextFloat() < bountyLevel / 32.0f) {
|
||||
if (world.rand.nextFloat() < bountyLevel / 16.0f) {
|
||||
List<? extends IMutation> allMutations = getRoot().getCombinations(this);
|
||||
if (!allMutations.isEmpty()) {
|
||||
List<IMutation> unresearchedMutations = new ArrayList<>();
|
||||
|
||||
@@ -11,34 +11,20 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.FakeAccessHandler;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.packets.PacketAccessUpdateEntity;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
|
||||
public class ContainerEntity<T extends Entity & IInventory> extends ContainerForestry {
|
||||
protected final T entity;
|
||||
private final IAccessHandler accessHandler;
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
|
||||
protected ContainerEntity(T entity) {
|
||||
this.entity = entity;
|
||||
|
||||
if (entity instanceof IRestrictedAccess) {
|
||||
accessHandler = ((IRestrictedAccess) entity).getAccessHandler();
|
||||
} else {
|
||||
accessHandler = FakeAccessHandler.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
protected ContainerEntity(T entity, InventoryPlayer playerInventory, int xInv, int yInv) {
|
||||
@@ -48,17 +34,14 @@ public class ContainerEntity<T extends Entity & IInventory> extends ContainerFor
|
||||
|
||||
@Override
|
||||
protected final boolean canAccess(EntityPlayer player) {
|
||||
return player != null && accessHandler.allowsAlteration(player);
|
||||
return player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return entity.isUseableByPlayer(entityplayer) && accessHandler.allowsViewing(entityplayer);
|
||||
return entity.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
private EnumAccess previousAccess;
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
@@ -74,17 +57,5 @@ public class ContainerEntity<T extends Entity & IInventory> extends ContainerFor
|
||||
|
||||
previousErrorStates = errorStates;
|
||||
}
|
||||
|
||||
if (entity instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccess = (IRestrictedAccess) entity;
|
||||
IAccessHandler accessHandler = restrictedAccess.getAccessHandler();
|
||||
EnumAccess access = accessHandler.getAccess();
|
||||
if (access != previousAccess) {
|
||||
IForestryPacketClient packet = new PacketAccessUpdateEntity(restrictedAccess, entity);
|
||||
sendPacketToListeners(packet);
|
||||
|
||||
previousAccess = access;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,19 +11,8 @@
|
||||
package forestry.core.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.FakeAccessHandler;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.packets.PacketAccessUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketGuiEnergy;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
@@ -31,20 +20,19 @@ import forestry.core.tiles.IPowerHandler;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public abstract class ContainerTile<T extends TileEntity> extends ContainerForestry {
|
||||
|
||||
protected final T tile;
|
||||
private final IAccessHandler accessHandler;
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
private int previousEnergyManagerData = 0;
|
||||
private int previousWorkCounter = 0;
|
||||
private int previousTicksPerWorkCycle = 0;
|
||||
|
||||
protected ContainerTile(T tile) {
|
||||
this.tile = tile;
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
accessHandler = ((IRestrictedAccess) tile).getAccessHandler();
|
||||
} else {
|
||||
accessHandler = FakeAccessHandler.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
protected ContainerTile(T tileForestry, InventoryPlayer playerInventory, int xInv, int yInv) {
|
||||
@@ -55,20 +43,14 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
|
||||
|
||||
@Override
|
||||
protected final boolean canAccess(EntityPlayer player) {
|
||||
return player != null && accessHandler.allowsAlteration(player);
|
||||
return player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return TileUtil.isUsableByPlayer(entityplayer, tile) && accessHandler.allowsViewing(entityplayer);
|
||||
return TileUtil.isUsableByPlayer(entityplayer, tile);
|
||||
}
|
||||
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
private int previousEnergyManagerData = 0;
|
||||
private EnumAccess previousAccess;
|
||||
private int previousWorkCounter = 0;
|
||||
private int previousTicksPerWorkCycle = 0;
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
@@ -96,18 +78,6 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccess = (IRestrictedAccess) tile;
|
||||
IAccessHandler accessHandler = restrictedAccess.getAccessHandler();
|
||||
EnumAccess access = accessHandler.getAccess();
|
||||
if (access != previousAccess) {
|
||||
IForestryPacketClient packet = new PacketAccessUpdate(restrictedAccess, tile);
|
||||
sendPacketToListeners(packet);
|
||||
|
||||
previousAccess = access;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile instanceof TilePowered) {
|
||||
boolean guiNeedsUpdate = false;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.api.genetics.IGenome;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -292,17 +293,9 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
HashMap<IMutation, IAllele> combinations = new HashMap<>();
|
||||
|
||||
ISpeciesRoot speciesRoot = individual.getGenome().getSpeciesRoot();
|
||||
|
||||
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getPrimary())) {
|
||||
combinations.put(mutation, individual.getGenome().getPrimary());
|
||||
}
|
||||
|
||||
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getSecondary())) {
|
||||
combinations.put(mutation, individual.getGenome().getSecondary());
|
||||
}
|
||||
IGenome genome = individual.getGenome();
|
||||
ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
|
||||
IAlleleSpecies species = genome.getPrimary();
|
||||
|
||||
int columnWidth = 50;
|
||||
int x = 0;
|
||||
@@ -310,17 +303,16 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile());
|
||||
|
||||
for (Map.Entry<IMutation, IAllele> mutation : combinations.entrySet()) {
|
||||
|
||||
if (breedingTracker.isDiscovered(mutation.getKey())) {
|
||||
drawMutationInfo(mutation.getKey(), mutation.getValue(), COLUMN_0 + x, breedingTracker);
|
||||
for (IMutation mutation : speciesRoot.getCombinations(species)) {
|
||||
if (breedingTracker.isDiscovered(mutation)) {
|
||||
drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
|
||||
} else {
|
||||
// Do not display secret undiscovered mutations.
|
||||
if (mutation.getKey().isSecret()) {
|
||||
if (mutation.isSecret()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
drawUnknownMutation(mutation.getKey(), COLUMN_0 + x, breedingTracker);
|
||||
drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
|
||||
}
|
||||
|
||||
x += columnWidth;
|
||||
|
||||
@@ -15,6 +15,7 @@ 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;
|
||||
@@ -27,7 +28,6 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.core.IErrorSource;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.ledgers.ClimateLedger;
|
||||
import forestry.core.gui.ledgers.HintLedger;
|
||||
@@ -106,8 +106,8 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory instanceof IRestrictedAccess) {
|
||||
ledgerManager.add(new OwnerLedger(ledgerManager, (IRestrictedAccess) inventory));
|
||||
if (inventory instanceof IOwnedTile) {
|
||||
ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnedTile) inventory));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,49 +10,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui.ledgers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IAccessOwnerListener;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
/**
|
||||
* Ledger displaying ownership information
|
||||
*/
|
||||
public class OwnerLedger extends Ledger implements IAccessOwnerListener {
|
||||
public class OwnerLedger extends Ledger {
|
||||
|
||||
private final IAccessHandler accessHandler;
|
||||
private final GameProfile owner;
|
||||
|
||||
public OwnerLedger(LedgerManager manager, IRestrictedAccess tile) {
|
||||
public OwnerLedger(LedgerManager manager, IOwnedTile tile) {
|
||||
super(manager, "owner");
|
||||
|
||||
this.accessHandler = tile.getAccessHandler();
|
||||
accessHandler.addOwnerListener(this);
|
||||
onOwnerSet(accessHandler.getOwner());
|
||||
}
|
||||
|
||||
private boolean isAccessButton(int mouseX, int mouseY) {
|
||||
|
||||
int shiftX = currentShiftX;
|
||||
int shiftY = currentShiftY + 44;
|
||||
|
||||
return mouseX >= shiftX && mouseX <= currentShiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + 12;
|
||||
this.owner = tile.getOwnerHandler().getOwner();
|
||||
this.maxHeight = 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return accessHandler.isOwned();
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,61 +42,18 @@ public class OwnerLedger extends Ledger implements IAccessOwnerListener {
|
||||
drawBackground(x, y);
|
||||
|
||||
// Draw icon
|
||||
EnumAccess accessType = accessHandler.getAccess();
|
||||
TextureAtlasSprite accessIcon = TextureManager.getInstance().getDefault("misc/access." + accessType.toString().toLowerCase(Locale.ENGLISH));
|
||||
TextureAtlasSprite accessIcon = TextureManager.getInstance().getDefault("misc/access.shared");
|
||||
drawSprite(accessIcon, x + 3, y + 4);
|
||||
|
||||
// Draw description
|
||||
if (!isFullyOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawHeader(Translator.translateToLocal("for.gui.owner"), x + 22, y + 8);
|
||||
|
||||
drawText(PlayerUtil.getOwnerName(accessHandler), x + 22, y + 20);
|
||||
|
||||
Minecraft minecraft = Proxies.common.getClientInstance();
|
||||
boolean playerIsOwner = accessHandler.isOwner(minecraft.thePlayer);
|
||||
if (playerIsOwner) {
|
||||
drawSubheader(Translator.translateToLocal("for.gui.access") + ':', x + 22, y + 32);
|
||||
// Access rules
|
||||
drawSprite(accessIcon, x + 20, y + 40);
|
||||
drawText(Translator.translateToLocal(accessType.getUnlocalizedName()), x + 38, y + 44);
|
||||
if (isFullyOpened()) {
|
||||
drawHeader(Translator.translateToLocal("for.gui.owner"), x + 22, y + 8);
|
||||
drawText(PlayerUtil.getOwnerName(owner), x + 22, y + 20);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return Translator.translateToLocal("for.gui.owner") + ": " + PlayerUtil.getOwnerName(accessHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMouseClicked(int x, int y, int mouseButton) {
|
||||
|
||||
if (isAccessButton(x, y)) {
|
||||
Minecraft minecraft = Proxies.common.getClientInstance();
|
||||
EntityPlayer player = minecraft.thePlayer;
|
||||
|
||||
return accessHandler.switchAccess(player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOwnerSet(GameProfile gameProfile) {
|
||||
Minecraft minecraft = Proxies.common.getClientInstance();
|
||||
boolean playerIsOwner = PlayerUtil.isSameGameProfile(minecraft.thePlayer.getGameProfile(), gameProfile);
|
||||
if (playerIsOwner) {
|
||||
maxHeight = 60;
|
||||
} else {
|
||||
maxHeight = 36;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
accessHandler.removeOwnerListener(this);
|
||||
return Translator.translateToLocal("for.gui.owner") + ": " + PlayerUtil.getOwnerName(owner);
|
||||
}
|
||||
}
|
||||
@@ -10,51 +10,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public class InventoryAdapterRestricted extends InventoryAdapter {
|
||||
private final IAccessHandler accessHandler;
|
||||
|
||||
public InventoryAdapterRestricted(int size, String name, IAccessHandler accessHandler) {
|
||||
public InventoryAdapterRestricted(int size, String name) {
|
||||
super(size, name);
|
||||
this.accessHandler = accessHandler;
|
||||
}
|
||||
|
||||
public InventoryAdapterRestricted(int size, String name, int stackLimit, IAccessHandler accessHandler) {
|
||||
public InventoryAdapterRestricted(int size, String name, int stackLimit) {
|
||||
super(size, name, stackLimit);
|
||||
this.accessHandler = accessHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return accessHandler.allowsViewing(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) {
|
||||
if (itemStack == null || !accessHandler.allowsPipeConnections()) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return canSlotAccept(slotIndex, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace(EnumFacing side) {
|
||||
if (!accessHandler.allowsPipeConnections()) {
|
||||
return Constants.SLOTS_NONE;
|
||||
}
|
||||
return super.getSlotsForFace(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
||||
if (itemStack == null || !accessHandler.allowsPipeConnections()) {
|
||||
if (itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
return isItemValidForSlot(slotIndex, itemStack);
|
||||
@@ -62,6 +41,6 @@ public class InventoryAdapterRestricted extends InventoryAdapter {
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
||||
return itemStack != null && accessHandler.allowsPipeConnections();
|
||||
return itemStack != null;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
|
||||
public class InventoryAdapterTile<T extends TileEntity & IRestrictedAccess> extends InventoryAdapterRestricted {
|
||||
public class InventoryAdapterTile<T extends TileEntity> extends InventoryAdapterRestricted {
|
||||
|
||||
protected final T tile;
|
||||
|
||||
@@ -25,7 +23,7 @@ public class InventoryAdapterTile<T extends TileEntity & IRestrictedAccess> exte
|
||||
}
|
||||
|
||||
public InventoryAdapterTile(T tile, int size, String name, int stackLimit) {
|
||||
super(size, name, stackLimit, tile.getAccessHandler());
|
||||
super(size, name, stackLimit);
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,20 +16,18 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.FakeAccessHandler;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.errors.FakeErrorLogic;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.owner.FakeOwnerHandler;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class FakeMultiblockController implements IMultiblockControllerInternal {
|
||||
@Override
|
||||
@@ -156,13 +154,8 @@ public abstract class FakeMultiblockController implements IMultiblockControllerI
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return FakeAccessHandler.getInstance();
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return FakeOwnerHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ package forestry.core.multiblock;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -22,12 +23,11 @@ import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
|
||||
// internal implementation of IMultiblockController
|
||||
public interface IMultiblockControllerInternal extends IMultiblockController, INbtWritable, INbtReadable, IRestrictedAccess, IErrorLogicSource, IClimatised, IStreamableGui {
|
||||
public interface IMultiblockControllerInternal extends IMultiblockController, INbtWritable, INbtReadable, IOwnedTile, IErrorLogicSource, IClimatised, IStreamableGui {
|
||||
/**
|
||||
* Attach a new part to this machine.
|
||||
* @param part The part to add.
|
||||
|
||||
@@ -10,11 +10,21 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.multiblock;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
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;
|
||||
@@ -23,33 +33,20 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.access.AccessHandler;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
|
||||
public abstract class MultiblockControllerForestry extends MultiblockControllerBase implements ISidedInventory, IRestrictedAccess, IErrorLogicSource, ILocatable {
|
||||
private final AccessHandler accessHandler;
|
||||
public abstract class MultiblockControllerForestry extends MultiblockControllerBase implements ISidedInventory, IOwnedTile, IErrorLogicSource, ILocatable {
|
||||
private final OwnerHandler ownerHandler;
|
||||
private final IErrorLogic errorLogic;
|
||||
|
||||
protected MultiblockControllerForestry(World world) {
|
||||
super(world);
|
||||
|
||||
this.accessHandler = new AccessHandler(this);
|
||||
this.ownerHandler = new OwnerHandler();
|
||||
this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return accessHandler;
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return ownerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,19 +87,21 @@ public abstract class MultiblockControllerForestry extends MultiblockControllerB
|
||||
}
|
||||
}
|
||||
|
||||
getAccessHandler().setOwner(owner);
|
||||
if (owner != null) {
|
||||
getOwnerHandler().setOwner(owner);
|
||||
}
|
||||
}
|
||||
|
||||
/* INbtWritable */
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
accessHandler.writeToNBT(data);
|
||||
ownerHandler.writeToNBT(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
accessHandler.readFromNBT(data);
|
||||
ownerHandler.readFromNBT(data);
|
||||
}
|
||||
|
||||
/* INVENTORY */
|
||||
|
||||
@@ -26,8 +26,6 @@ public enum PacketIdClient implements IPacketId {
|
||||
GUI_LAYOUT_SELECT,
|
||||
GUI_ENERGY,
|
||||
SOCKET_UPDATE,
|
||||
ACCESS_UPDATE,
|
||||
ACCESS_UPDATE_ENTITY,
|
||||
|
||||
// Core Tile Entities
|
||||
TILE_FORESTRY_UPDATE,
|
||||
|
||||
@@ -21,8 +21,6 @@ public enum PacketIdServer implements IPacketId {
|
||||
// Core Gui
|
||||
GUI_SELECTION_REQUEST,
|
||||
PIPETTE_CLICK,
|
||||
ACCESS_SWITCH,
|
||||
ACCESS_SWITCH_ENTITY,
|
||||
CHIPSET_CLICK,
|
||||
SOLDERING_IRON_CLICK,
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import forestry.core.network.packets.PacketAccessSwitch;
|
||||
import forestry.core.network.packets.PacketAccessSwitchEntity;
|
||||
import forestry.core.network.packets.PacketAccessUpdate;
|
||||
import forestry.core.network.packets.PacketAccessUpdateEntity;
|
||||
import forestry.core.network.packets.PacketChipsetClick;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
@@ -41,8 +37,6 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
registerClientPacket(new PacketGuiLayoutSelect());
|
||||
registerClientPacket(new PacketGuiEnergy());
|
||||
registerClientPacket(new PacketSocketUpdate());
|
||||
registerClientPacket(new PacketAccessUpdate());
|
||||
registerClientPacket(new PacketAccessUpdateEntity());
|
||||
registerClientPacket(new PacketTileStream());
|
||||
registerClientPacket(new PacketItemStackDisplay());
|
||||
registerClientPacket(new PacketFXSignal());
|
||||
@@ -51,8 +45,6 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
|
||||
registerServerPacket(new PacketGuiSelectRequest());
|
||||
registerServerPacket(new PacketPipetteClick());
|
||||
registerServerPacket(new PacketAccessSwitch());
|
||||
registerServerPacket(new PacketAccessSwitchEntity());
|
||||
registerServerPacket(new PacketChipsetClick());
|
||||
registerServerPacket(new PacketSolderingIronClick());
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.tiles.ILocatable;
|
||||
|
||||
public class PacketAccessSwitch extends PacketCoordinates implements IForestryPacketServer {
|
||||
|
||||
public PacketAccessSwitch() {
|
||||
}
|
||||
|
||||
public PacketAccessSwitch(ILocatable tile) {
|
||||
super(tile.getCoordinates());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
|
||||
restrictedAccessTile.getAccessHandler().switchAccess(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.ACCESS_SWITCH;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
|
||||
public class PacketAccessSwitchEntity extends PacketEntityUpdate implements IForestryPacketServer {
|
||||
|
||||
public PacketAccessSwitchEntity() {
|
||||
}
|
||||
|
||||
public PacketAccessSwitchEntity(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
Entity target = getTarget(player.worldObj);
|
||||
if (target instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) target;
|
||||
restrictedAccessTile.getAccessHandler().switchAccess(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.ACCESS_SWITCH_ENTITY;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
|
||||
public class PacketAccessUpdate extends PacketCoordinates implements IForestryPacketClient {
|
||||
private IAccessHandler accessHandler;
|
||||
|
||||
public PacketAccessUpdate() {
|
||||
}
|
||||
|
||||
public PacketAccessUpdate(IRestrictedAccess restrictedAccess, TileEntity tile) {
|
||||
super(tile);
|
||||
accessHandler = restrictedAccess.getAccessHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
accessHandler.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
|
||||
restrictedAccessTile.getAccessHandler().readData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdClient getPacketId() {
|
||||
return PacketIdClient.ACCESS_UPDATE;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
|
||||
public class PacketAccessUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient {
|
||||
private IAccessHandler accessHandler;
|
||||
|
||||
public PacketAccessUpdateEntity() {
|
||||
}
|
||||
|
||||
public PacketAccessUpdateEntity(IRestrictedAccess restrictedAccess, Entity entity) {
|
||||
super(entity);
|
||||
accessHandler = restrictedAccess.getAccessHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
accessHandler.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
Entity tile = getTarget(player.worldObj);
|
||||
|
||||
if (tile instanceof IRestrictedAccess) {
|
||||
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
|
||||
restrictedAccessTile.getAccessHandler().readData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdClient getPacketId() {
|
||||
return PacketIdClient.ACCESS_UPDATE_ENTITY;
|
||||
}
|
||||
}
|
||||
+40
-17
@@ -1,17 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* 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.access;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public interface IAccessOwnerListener {
|
||||
void onOwnerSet(GameProfile gameProfile);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* 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.owner;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class FakeOwnerHandler implements IOwnerHandler {
|
||||
private static FakeOwnerHandler instance;
|
||||
|
||||
public static FakeOwnerHandler getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new FakeOwnerHandler();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private FakeOwnerHandler() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package forestry.core.owner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.DataSerializer;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
|
||||
public class GameProfileDataSerializer implements DataSerializer<Optional<GameProfile>> {
|
||||
public static final GameProfileDataSerializer INSTANCE = new GameProfileDataSerializer();
|
||||
|
||||
public static void register() {
|
||||
DataSerializers.registerSerializer(INSTANCE);
|
||||
}
|
||||
|
||||
private GameProfileDataSerializer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buf, Optional<GameProfile> value) {
|
||||
if (!value.isPresent()) {
|
||||
buf.writeBoolean(false);
|
||||
} else {
|
||||
buf.writeBoolean(true);
|
||||
GameProfile gameProfile = value.get();
|
||||
buf.writeUuid(gameProfile.getId());
|
||||
buf.writeString(gameProfile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GameProfile> read(PacketBuffer buf) throws IOException {
|
||||
if (buf.readBoolean()) {
|
||||
UUID uuid = buf.readUuid();
|
||||
String name = buf.readStringFromBuffer(1024);
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
return Optional.of(gameProfile);
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataParameter<Optional<GameProfile>> createKey(int id) {
|
||||
return new DataParameter<>(id, this);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -8,8 +8,8 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.tiles;
|
||||
package forestry.core.owner;
|
||||
|
||||
public interface IMailContainer {
|
||||
boolean hasMail();
|
||||
public interface IOwnedTile {
|
||||
IOwnerHandler getOwnerHandler();
|
||||
}
|
||||
+2
-10
@@ -8,24 +8,16 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
package forestry.core.owner;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public interface IOwnable {
|
||||
|
||||
boolean isOwned();
|
||||
|
||||
public interface IOwnerHandler {
|
||||
@Nullable
|
||||
GameProfile getOwner();
|
||||
|
||||
void setOwner(@Nonnull GameProfile owner);
|
||||
|
||||
boolean isOwner(EntityPlayer player);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*******************************************************************************
|
||||
* 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.owner;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
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.utils.PlayerUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class OwnerHandler implements IOwnerHandler, IStreamable, INbtWritable, INbtReadable {
|
||||
private GameProfile owner = null;
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
if (owner == null) {
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
data.writeLong(owner.getId().getMostSignificantBits());
|
||||
data.writeLong(owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(owner.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
if (data.readBoolean()) {
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
setOwner(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
if (data.hasKey("owner")) {
|
||||
GameProfile owner = PlayerUtil.readGameProfileFromNBT(data.getCompoundTag("owner"));
|
||||
if (owner != null) {
|
||||
setOwner(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
if (this.owner != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
PlayerUtil.writeGameProfile(nbt, owner);
|
||||
data.setTag("owner", nbt);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -64,11 +64,6 @@ public class ProxyClient extends ProxyCommon {
|
||||
return getClientInstance().theWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockReachDistance(EntityPlayer entityplayer) {
|
||||
if (entityplayer instanceof EntityPlayerSP) {
|
||||
|
||||
@@ -62,12 +62,6 @@ public class ProxyCommon {
|
||||
return new File(".");
|
||||
}
|
||||
|
||||
public boolean isOp(EntityPlayer player) {
|
||||
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
UserListOpsEntry userlistopsentry = server.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
|
||||
return userlistopsentry.getPermissionLevel() >= server.getOpPermissionLevel();
|
||||
}
|
||||
|
||||
public double getBlockReachDistance(EntityPlayer entityplayer) {
|
||||
return 4f;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -251,22 +252,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -33,6 +34,7 @@ import forestry.core.utils.BlockUtil;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileEngine extends TileBase implements IEnergyConnection, IActivatable {
|
||||
private static final int CANT_SEND_ENERGY_TIME = 20;
|
||||
@@ -294,4 +296,19 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
public EnergyManager getEnergyManager() {
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -35,10 +37,7 @@ import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.core.access.AccessHandler;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.errors.ErrorLogic;
|
||||
import forestry.core.gui.IGuiHandlerTile;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
@@ -51,11 +50,9 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.NBTUtilForestry;
|
||||
|
||||
//@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
|
||||
public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ISidedInventory, IFilterSlotDelegate, IRestrictedAccess, ITitled, ILocatable, IGuiHandlerTile, ITickable {
|
||||
private static final EnumFacing[] forgeDirections = EnumFacing.values();
|
||||
public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ISidedInventory, IFilterSlotDelegate, ITitled, ILocatable, IGuiHandlerTile, ITickable {
|
||||
private static final Random rand = new Random();
|
||||
|
||||
private final AccessHandler accessHandler = new AccessHandler(this);
|
||||
private final ErrorLogic errorHandler = new ErrorLogic();
|
||||
private final AdjacentTileCache tileCache = new AdjacentTileCache(this);
|
||||
@Nonnull
|
||||
@@ -115,9 +112,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
inventory.readFromNBT(data);
|
||||
accessHandler.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -125,7 +120,6 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
data = super.writeToNBT(data);
|
||||
inventory.writeToNBT(data);
|
||||
accessHandler.writeToNBT(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -201,20 +195,6 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IAccessHandler getAccessHandler() {
|
||||
return accessHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
|
||||
// pipes connected to this need to update
|
||||
worldObj.notifyBlockOfStateChange(getPos(), blockType);
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/* NAME */
|
||||
|
||||
/**
|
||||
@@ -352,8 +332,9 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
SidedInvWrapper sidedInvWrapper = new SidedInvWrapper(inventory, facing);
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(sidedInvWrapper);
|
||||
@@ -362,8 +343,8 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability(capability, facing);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -27,6 +28,7 @@ import forestry.core.render.TankRenderInfo;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
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 {
|
||||
@@ -218,4 +220,19 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
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);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
@@ -51,12 +52,19 @@ public abstract class BlockUtil {
|
||||
}
|
||||
|
||||
public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) {
|
||||
if (!(tile instanceof IEnergyReceiver) && !(tile instanceof TileEngine)) {
|
||||
return false;
|
||||
}
|
||||
if (tile != null) {
|
||||
if (EnergyManager.TESLA_CONSUMER != null) {
|
||||
if (tile.hasCapability(EnergyManager.TESLA_CONSUMER, side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnergyConnection receptor = (IEnergyConnection) tile;
|
||||
return receptor.canConnectEnergy(side);
|
||||
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) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.utils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
@@ -36,15 +37,6 @@ import forestry.plugins.ForestryPluginUids;
|
||||
|
||||
public abstract class InventoryUtil {
|
||||
|
||||
public static ItemStack depleteItem(ItemStack stack) {
|
||||
if (stack.stackSize == 1) {
|
||||
return stack.getItem().getContainerItem(stack);
|
||||
} else {
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return stack.getItemDamage() == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
@@ -206,7 +198,7 @@ public abstract class InventoryUtil {
|
||||
* If the inventory doesn't have all the required items, returns false without removing anything.
|
||||
* If stowContainer is true, items with containers will have their container stowed.
|
||||
*/
|
||||
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools, boolean doRemove) {
|
||||
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools, boolean doRemove) {
|
||||
ItemStack[] stock = getStacks(inventory);
|
||||
|
||||
if (doRemove) {
|
||||
@@ -217,7 +209,7 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
public static ItemStack[] removeSets(IInventory inventory, int count, ItemStack[] set, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
ItemStack[] removed = new ItemStack[set.length];
|
||||
ItemStack[] stock = getStacks(inventory);
|
||||
|
||||
@@ -247,7 +239,7 @@ public abstract class InventoryUtil {
|
||||
/**
|
||||
* Private Helper for removeSetsFromInventory. Assumes removal is possible.
|
||||
*/
|
||||
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
for (int j = 0; j < inventory.getSizeInventory(); j++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(j);
|
||||
if (stackInSlot == null) {
|
||||
@@ -496,7 +488,7 @@ public abstract class InventoryUtil {
|
||||
return added;
|
||||
}
|
||||
|
||||
public static void stowContainerItem(ItemStack itemstack, IInventory stowing, int slotIndex, EntityPlayer player) {
|
||||
public static void stowContainerItem(ItemStack itemstack, IInventory stowing, int slotIndex, @Nullable EntityPlayer player) {
|
||||
if (!itemstack.getItem().hasContainerItem(itemstack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -335,10 +335,6 @@ public abstract class ItemStackUtil {
|
||||
* Compare two item stacks for crafting equivalency.
|
||||
*/
|
||||
public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison, boolean oreDictionary, boolean craftingTools) {
|
||||
if (isCraftingEquivalent(base, comparison)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base == null || comparison == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -347,6 +343,10 @@ public abstract class ItemStackUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCraftingEquivalent(base, comparison)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.hasTagCompound() && !base.getTagCompound().hasNoTags()) {
|
||||
if (!ItemStack.areItemStacksEqual(base, comparison)) {
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
|
||||
import forestry.core.access.IOwnable;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
|
||||
public abstract class PlayerUtil {
|
||||
|
||||
@@ -46,8 +46,7 @@ public abstract class PlayerUtil {
|
||||
return player1.getName() != null && player1.getName().equals(player2.getName());
|
||||
}
|
||||
|
||||
public static String getOwnerName(IOwnable ownable) {
|
||||
GameProfile profile = ownable.getOwner();
|
||||
public static String getOwnerName(GameProfile profile) {
|
||||
if (profile == null) {
|
||||
return Translator.translateToLocal("for.gui.derelict");
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,9 @@ package forestry.energy;
|
||||
|
||||
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;
|
||||
@@ -13,11 +16,25 @@ import forestry.core.network.IStreamable;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaConsumer", modid = "Tesla"),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaProducer", modid = "Tesla"),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaHolder", modid = "Tesla")
|
||||
})
|
||||
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;
|
||||
|
||||
public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreamable {
|
||||
private enum EnergyTransferMode {
|
||||
EXTRACT, RECEIVE, BOTH
|
||||
}
|
||||
@@ -63,7 +80,6 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
|
||||
/* NBT */
|
||||
public EnergyManager readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound energyManagerNBT = nbt.getCompoundTag("EnergyManager");
|
||||
NBTTagCompound energyStorageNBT = energyManagerNBT.getCompoundTag("EnergyStorage");
|
||||
energyStorage.readFromNBT(energyStorageNBT);
|
||||
@@ -72,7 +88,6 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound energyStorageNBT = new NBTTagCompound();
|
||||
energyStorage.writeToNBT(energyStorageNBT);
|
||||
|
||||
@@ -188,16 +203,18 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
*/
|
||||
public int sendEnergy(EnumFacing orientation, TileEntity tile, int amount, boolean simulate) {
|
||||
int sent = 0;
|
||||
if (BlockUtil.isEnergyReceiverOrEngine(orientation.getOpposite(), tile)) {
|
||||
if (tile != null) {
|
||||
int extractable = energyStorage.extractEnergy(amount, true);
|
||||
if (extractable > 0) {
|
||||
|
||||
if (tile instanceof IEnergyReceiver) {
|
||||
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(orientation.getOpposite(), extractable, simulate);
|
||||
} else if (tile instanceof TileEngine) {
|
||||
sent = receptor.receiveEnergy(side, extractable, simulate);
|
||||
} else if (tile instanceof TileEngine) { // engine chaining
|
||||
TileEngine receptor = (TileEngine) tile;
|
||||
sent = receptor.getEnergyManager().receiveEnergy(orientation.getOpposite(), extractable, simulate);
|
||||
sent = receptor.getEnergyManager().receiveEnergy(side, extractable, simulate);
|
||||
}
|
||||
|
||||
energyStorage.extractEnergy(sent, simulate);
|
||||
@@ -219,4 +236,62 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
public void generateEnergy(int amount) {
|
||||
energyStorage.modifyEnergyStored(amount);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
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 = "Tesla")
|
||||
@Override
|
||||
public long givePower(long power, boolean simulated) {
|
||||
if (!canReceive()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.receiveEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long takePower(long power, boolean simulated) {
|
||||
if (!canExtract()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.extractEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long getStoredPower() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return energyStorage.getMaxEnergyStored();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package forestry.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class EnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
if (energy < 0) {
|
||||
energy = 0;
|
||||
}
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public EnergyStorage setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxExtract(int maxExtract) {
|
||||
this.maxExtract = maxExtract;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
if (energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (energy < 0) {
|
||||
this.energy = 0;
|
||||
} else {
|
||||
this.energy = energy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyStorage */
|
||||
public int receiveEnergy(long maxReceive, boolean simulate) {
|
||||
int energyReceived = (int) Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
public int extractEnergy(long maxExtract, boolean simulate) {
|
||||
int energyExtracted = (int) Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
}
|
||||
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
public int getEnergyStored() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,10 @@
|
||||
package forestry.energy.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
@@ -293,22 +295,17 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.energy.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -215,15 +216,16 @@ public class TileEuGenerator extends TileBase implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ package forestry.factory.inventory;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
|
||||
public class InventoryGhostCrafting<T extends TileEntity & IRestrictedAccess> extends InventoryAdapterTile<T> {
|
||||
public class InventoryGhostCrafting<T extends TileEntity> extends InventoryAdapterTile<T> {
|
||||
public final static int SLOT_CRAFTING_1 = 0;
|
||||
public final static int SLOT_CRAFTING_COUNT = 9;
|
||||
public final static int SLOT_CRAFTING_RESULT = 9;
|
||||
|
||||
@@ -69,9 +69,9 @@ public class InventorySqueezer extends InventoryAdapterTile<TileSqueezer> {
|
||||
return InventoryUtil.getStacks(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT);
|
||||
}
|
||||
|
||||
public boolean removeResources(ItemStack[] stacks, EntityPlayer player) {
|
||||
public boolean removeResources(ItemStack[] stacks) {
|
||||
IInventory inventory = new InventoryMapper(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT);
|
||||
return InventoryUtil.removeSets(inventory, 1, stacks, player, false, true, false, true);
|
||||
return InventoryUtil.removeSets(inventory, 1, stacks, null, false, true, false, true);
|
||||
}
|
||||
|
||||
public boolean addRemnant(ItemStack remnant, boolean doAdd) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -167,22 +168,17 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -187,10 +187,9 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
}
|
||||
|
||||
EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
ItemStack[] craftingSets = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
|
||||
IInventory inventory = new InventoryMapper(getInternalInventory(), InventoryCarpenter.SLOT_INVENTORY_1, InventoryCarpenter.SLOT_INVENTORY_COUNT);
|
||||
return InventoryUtil.removeSets(inventory, 1, craftingSets, player, true, true, false, doRemove);
|
||||
return InventoryUtil.removeSets(inventory, 1, craftingSets, null, true, true, false, doRemove);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
@@ -250,22 +249,17 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -320,22 +321,17 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -324,21 +325,16 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -520,21 +521,16 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -161,22 +162,17 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,18 +11,9 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
@@ -42,11 +33,18 @@ import forestry.core.render.TankRenderInfo;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.factory.gui.ContainerSqueezer;
|
||||
import forestry.factory.gui.GuiSqueezer;
|
||||
import forestry.factory.inventory.InventorySqueezer;
|
||||
import forestry.factory.recipes.SqueezerRecipeManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
|
||||
public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, ISpeedUpgradable {
|
||||
private static final int TICKS_PER_RECIPE_TIME = 1;
|
||||
@@ -130,8 +128,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
|
||||
@Override
|
||||
public boolean workCycle() {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
if (!inventory.removeResources(currentRecipe.getResources(), player)) {
|
||||
if (!inventory.removeResources(currentRecipe.getResources())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -257,22 +254,17 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -187,22 +188,17 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,13 +14,6 @@ import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
@@ -36,6 +29,12 @@ import forestry.factory.inventory.InventoryGhostCrafting;
|
||||
import forestry.factory.inventory.InventoryWorktable;
|
||||
import forestry.factory.recipes.MemorizedRecipe;
|
||||
import forestry.factory.recipes.RecipeMemory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
private RecipeMemory recipeMemory;
|
||||
@@ -157,30 +156,15 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
|
||||
@Override
|
||||
public void onCraftingComplete(EntityPlayer player) {
|
||||
IInventory craftingInventory = getCraftingDisplay();
|
||||
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
|
||||
ItemStack itemStack = craftingInventory.getStackInSlot(i);
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
ForgeHooks.setCraftingPlayer(player);
|
||||
ItemStack[] remainingItems = CraftingManager.getInstance().getRemainingItems(currentRecipe.getCraftMatrix(), player.worldObj);
|
||||
ForgeHooks.setCraftingPlayer(null);
|
||||
|
||||
ItemStack container = null;
|
||||
|
||||
if (itemStack.getItem().hasContainerItem(itemStack)) {
|
||||
container = ForgeHooks.getContainerItem(itemStack);
|
||||
} else if (itemStack.stackSize > 1) {
|
||||
// TerraFirmaCraft's crafting event handler does some tricky stuff with its tools.
|
||||
// It sets the tool's stack size to 2 instead of using a container.
|
||||
container = ItemStackUtil.createSplitStack(itemStack, itemStack.stackSize - 1);
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
if (container == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!InventoryUtil.tryAddStack(this, container, true)) {
|
||||
player.dropItem(container, false);
|
||||
for (ItemStack remainingItem : remainingItems) {
|
||||
if (remainingItem != null) {
|
||||
if (!InventoryUtil.tryAddStack(this, remainingItem, true)) {
|
||||
player.dropItem(remainingItem, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +192,7 @@ public class BlockFarm extends BlockStructure {
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return blockState.getValue(META) == EnumFarmBlockType.CONTROL;
|
||||
return state.getValue(META) == EnumFarmBlockType.CONTROL;
|
||||
}
|
||||
|
||||
public ItemStack get(EnumFarmBlockType type, int amount) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
public FarmLogicRubber() {
|
||||
if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
|
||||
Log.warning("Failed to init a farm logic %s since IC2 was not found", getClass().getName());
|
||||
Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!BlockUtil.isReplaceableBlock(state, world, platformPosition)) {
|
||||
if (!BlockUtil.isReplaceableBlock(state, world, position)) {
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
world.setBlockToAir(position);
|
||||
return trySetSoil(world, farmHousing, position);
|
||||
|
||||
@@ -32,7 +32,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
@@ -57,7 +56,6 @@ import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.multiblock.IFarmComponent;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
@@ -342,20 +340,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return new BlockPos(coord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
|
||||
// pipes connected to this need to update
|
||||
for (IMultiblockComponent part : connectedParts) {
|
||||
if (part instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity) part;
|
||||
tile.getWorld().notifyBlockOfStateChange(tile.getPos(), tile.getBlockType());
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
tankManager.writeData(data);
|
||||
@@ -483,11 +467,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
continue;
|
||||
}
|
||||
|
||||
// Allow listeners to cancel this cycle.
|
||||
if (isCycleCanceledByListeners(logic, farmSide, farmListeners)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always try to collect windfall.
|
||||
if (collectWindfall(logic)) {
|
||||
farmWorkStatus.didWork = true;
|
||||
@@ -504,7 +483,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
harvestProvider = logic;
|
||||
}
|
||||
} else if (stage == Stage.CULTIVATE) {
|
||||
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic);
|
||||
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic, farmSide);
|
||||
}
|
||||
|
||||
if (farmWorkStatus.didWork) {
|
||||
@@ -622,31 +601,37 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
private static class FarmWorkStatus {
|
||||
public boolean didWork = false;
|
||||
public boolean hasFarmland = false;
|
||||
public boolean hasFertilizer = false;
|
||||
public boolean hasLiquid = false;
|
||||
public boolean hasFertilizer = true;
|
||||
public boolean hasLiquid = true;
|
||||
}
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, IFarmLogic logic) {
|
||||
float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
|
||||
final int fertilizerConsumption = logic.getFertilizerConsumption();
|
||||
int liquidConsumption = logic.getWaterConsumption(hydrationModifier);
|
||||
FluidStack liquid = new FluidStack(FluidRegistry.WATER, liquidConsumption);
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, IFarmLogic logic, FarmDirection farmSide) {
|
||||
boolean hasFarmland = false;
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() <= 0) {
|
||||
break;
|
||||
} else {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFarmland && !isCycleCanceledByListeners(logic, farmSide, farmListeners)) {
|
||||
final float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
final int fertilizerConsumption = logic.getFertilizerConsumption();
|
||||
final int liquidConsumption = logic.getWaterConsumption(hydrationModifier);
|
||||
final FluidStack liquid = new FluidStack(FluidRegistry.WATER, liquidConsumption);
|
||||
|
||||
for (FarmTarget target : farmTargets) {
|
||||
// Check fertilizer and water
|
||||
if (!fertilizerManager.hasFertilizer(fertilizerConsumption)) {
|
||||
farmWorkStatus.hasFertilizer = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (liquid.amount > 0 && !hasLiquid(liquid)) {
|
||||
farmWorkStatus.hasLiquid = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -660,9 +645,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
}
|
||||
|
||||
farmWorkStatus.hasLiquid = liquid.amount <= 0 || hasLiquid(liquid);
|
||||
farmWorkStatus.hasFertilizer = fertilizerManager.hasFertilizer(fertilizerConsumption);
|
||||
|
||||
return farmWorkStatus;
|
||||
}
|
||||
|
||||
@@ -791,7 +773,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner());
|
||||
return inventory.plantGermling(germling, player, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ package forestry.farming.multiblock;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.multiblock.IFarmController;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
@@ -22,7 +22,7 @@ import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
|
||||
public interface IFarmControllerInternal extends IFarmController, IMultiblockControllerInternal, ISocketable, IClimatised, IRestrictedAccess, IStreamableGui {
|
||||
public interface IFarmControllerInternal extends IFarmController, IMultiblockControllerInternal, ISocketable, IClimatised, IOwnedTile, IStreamableGui {
|
||||
IFarmLedgerDelegate getFarmLedgerDelegate();
|
||||
|
||||
IInventoryAdapter getInternalInventory();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
private final IInventory fertilizerInventory;
|
||||
|
||||
public InventoryFarm(FarmController farmController) {
|
||||
super(SLOT_COUNT, "Items", farmController.getAccessHandler());
|
||||
super(SLOT_COUNT, "Items");
|
||||
this.farmController = farmController;
|
||||
|
||||
this.resourcesInventory = new InventoryMapper(this, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT);
|
||||
@@ -94,7 +94,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner());
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -26,9 +28,6 @@ import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.multiblock.IFarmComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.access.IRestrictedAccess;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.IHintSource;
|
||||
@@ -44,7 +43,7 @@ import forestry.farming.gui.GuiFarm;
|
||||
import forestry.farming.models.EnumFarmBlockTexture;
|
||||
import forestry.farming.multiblock.MultiblockLogicFarm;
|
||||
|
||||
public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLogicFarm> implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IRestrictedAccess, ITitled {
|
||||
public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLogicFarm> implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled {
|
||||
|
||||
private EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.BRICK_STONE;
|
||||
|
||||
@@ -166,13 +165,8 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return getMultiblockLogic().getController().getAccessHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess);
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return getMultiblockLogic().getController().getOwnerHandler();
|
||||
}
|
||||
|
||||
/* ITitled */
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import forestry.farming.blocks.BlockFarm;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -42,15 +44,11 @@ public class TileFarmControl extends TileFarm implements IFarmComponent.Listener
|
||||
|
||||
@Override
|
||||
public boolean cancelTask(IFarmLogic logic, FarmDirection direction) {
|
||||
return hasRedstoneSignal(direction.getFacing()) || hasRedstoneSignal(EnumFacing.UP) || hasRedstoneSignal(EnumFacing.DOWN);
|
||||
}
|
||||
|
||||
private boolean hasRedstoneSignal(EnumFacing direction) {
|
||||
BlockPos side = tile.getPos().offset(direction);
|
||||
EnumFacing dir = direction.getOpposite();
|
||||
World world = tile.getWorld();
|
||||
|
||||
return world.getRedstonePower(side, dir) > 0 || world.getStrongPower(side, dir) > 0;
|
||||
BlockPos pos = tile.getPos();
|
||||
EnumFacing facing = direction.getFacing();
|
||||
World world = tile.getWorldObj();
|
||||
IBlockState blockState = world.getBlockState(pos.offset(facing));
|
||||
return !(blockState.getBlock() instanceof BlockFarm) && world.getRedstonePower(pos, facing) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -21,6 +22,7 @@ import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public class TileFarmGearbox extends TileFarm implements IEnergyReceiver, IEnergyHandler, IFarmComponent.Active {
|
||||
|
||||
@@ -117,4 +119,18 @@ public class TileFarmGearbox extends TileFarm implements IEnergyReceiver, IEnerg
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -112,22 +112,18 @@ public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapper
|
||||
if (!(tile instanceof TileGreenhouseDoor)) {
|
||||
return false;
|
||||
}
|
||||
TileGreenhouseDoor door = (TileGreenhouseDoor) tile;
|
||||
if (!door.getAccessHandler().allowsInteracting(playerIn)) {
|
||||
|
||||
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
|
||||
IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
|
||||
|
||||
if (iblockstate.getBlock() != this) {
|
||||
return false;
|
||||
} else {
|
||||
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
|
||||
IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
|
||||
|
||||
if (iblockstate.getBlock() != this) {
|
||||
return false;
|
||||
} else {
|
||||
state = iblockstate.cycleProperty(OPEN);
|
||||
worldIn.setBlockState(blockpos, state, 2);
|
||||
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
|
||||
worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1005 : 1011, pos, 0);
|
||||
return true;
|
||||
}
|
||||
state = iblockstate.cycleProperty(OPEN);
|
||||
worldIn.setBlockState(blockpos, state, 2);
|
||||
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
|
||||
worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1005 : 1011, pos, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class InventoryGreenhouse extends InventoryAdapterRestricted {
|
||||
private final GreenhouseController greenhouseController;
|
||||
|
||||
public InventoryGreenhouse(GreenhouseController greenhouseController) {
|
||||
super(1, "Items", greenhouseController.getAccessHandler());
|
||||
super(1, "Items");
|
||||
this.greenhouseController = greenhouseController;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
@@ -246,20 +245,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
protected void onAttachedPartWithMultiblockData(IMultiblockComponent part, NBTTagCompound data) {
|
||||
readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
|
||||
// pipes connected to this need to update
|
||||
for (IMultiblockComponent part : connectedParts) {
|
||||
if (part instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity) part;
|
||||
worldObj.notifyBlockOfStateChange(tile.getPos(), tile.getBlockType());
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/* GUI DATA */
|
||||
@Override
|
||||
|
||||
Loaded 100 of 113 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user