Compare commits

..
7 Commits
85 changed files with 567 additions and 1420 deletions

No files matched your search

+1 -1
View File
@@ -8,4 +8,4 @@ ic2_version=2.6.5-ex110
version_major=5
version_minor=1
version_patch=9
version_patch=11
+1 -1
Submodule lang updated: 2d88011e4a...82c5455d7b.
+3 -1
View File
@@ -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)
@@ -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
@@ -42,7 +42,7 @@ public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implement
@Nonnull
private final IBeeListener beeListener = new ApiaryBeeListener(this);
@Nonnull
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
private final InventoryApiary inventory = new InventoryApiary();
@SuppressWarnings("unused")
public EntityMinecartApiary(World world) {
@@ -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);
}
}
@@ -34,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) {
@@ -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;
@@ -72,7 +70,7 @@ 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());
@@ -342,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();
@@ -385,7 +369,7 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
@Override
public GameProfile getOwner() {
return getAccessHandler().getOwner();
return getOwnerHandler().getOwner();
}
@Override
@@ -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);
@@ -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.util.math.BlockPos;
@@ -34,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;
@@ -47,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() {
@@ -143,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
@@ -36,7 +36,7 @@ public class TileApiary extends TileBeeHousingBase implements IApiary {
@Nonnull
private final IBeeListener beeListener = new ApiaryBeeListener(this);
@Nonnull
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
private final InventoryApiary inventory = new InventoryApiary();
public TileApiary() {
super("apiary");
@@ -37,7 +37,7 @@ public class TileBeeHouse extends TileBeeHousingBase {
super("bee.house");
this.beeListener = new DefaultBeeListener();
beeInventory = new InventoryBeeHousing(12, getAccessHandler());
beeInventory = new InventoryBeeHousing(12);
beeInventory.disableAutomation();
setInternalInventory(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);
@@ -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() {
@@ -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.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;
}
}
@@ -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);
}
}
@@ -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();
}
@@ -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;
}
@@ -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 */
/**
@@ -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 {
@@ -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) {
@@ -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 */
@@ -14,16 +14,6 @@ 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;
@@ -43,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;
@@ -131,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;
}
@@ -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);
}
}
}
@@ -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);
@@ -789,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 */
@@ -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
@@ -17,14 +17,14 @@ import java.util.Set;
import forestry.api.greenhouse.IGreenhouseState;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IGreenhouseController;
import forestry.core.access.IRestrictedAccess;
import forestry.core.owner.IOwnedTile;
import forestry.core.fluids.ITankManager;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.multiblock.IMultiblockControllerInternal;
import forestry.core.network.IStreamableGui;
import forestry.energy.EnergyManager;
public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IRestrictedAccess, IStreamableGui {
public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IOwnedTile, IStreamableGui {
/**
* @return The inventory of the controller.
@@ -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.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -29,9 +31,6 @@ import forestry.api.core.IErrorLogicSource;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
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;
@@ -49,7 +48,7 @@ import forestry.greenhouse.gui.GuiGreenhouse;
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
public abstract class TileGreenhouse extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IRestrictedAccess, ITitled, ICamouflageHandler, ICamouflagedTile {
public abstract class TileGreenhouse extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile {
private ItemStack camouflageBlock;
@@ -172,13 +171,8 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
}
@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,20 +10,18 @@
******************************************************************************/
package forestry.greenhouse.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorLogicSource;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.core.access.EnumAccess;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.IOwnedTile;
import forestry.core.multiblock.MultiblockTileEntityForestry;
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
public class TileGreenhouseDoor extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent.Door, IErrorLogicSource, IRestrictedAccess {
public class TileGreenhouseDoor extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent.Door, IErrorLogicSource, IOwnedTile {
public TileGreenhouseDoor() {
super(new MultiblockLogicGreenhouse());
@@ -47,13 +45,8 @@ public class TileGreenhouseDoor extends MultiblockTileEntityForestry<MultiblockL
}
@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
@@ -14,6 +14,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import forestry.core.owner.IOwnerHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -41,9 +42,7 @@ import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.api.multiblock.MultiblockTileEntityBase;
import forestry.core.access.EnumAccess;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.owner.IOwnedTile;
import forestry.core.config.Config;
import forestry.core.gui.IHintSource;
import forestry.core.proxy.Proxies;
@@ -60,7 +59,7 @@ import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver;
public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IErrorLogicSource, IRestrictedAccess, ICamouflageHandler, ICamouflagedTile, IFluidHandler, IEnergyProvider, IEnergyReceiver {
public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IHintSource, IErrorLogicSource, IOwnedTile, ICamouflageHandler, ICamouflagedTile, IFluidHandler, IEnergyProvider, IEnergyReceiver {
EnumFacing outwards;
private ItemStack camouflageBlock;
@@ -197,13 +196,8 @@ public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogi
}
@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
@@ -196,7 +196,7 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
TileCocoon cocoon = (TileCocoon) tile;
cocoon.setCaterpillar(nursery.getCaterpillar());
cocoon.setOwner(owner);
cocoon.getOwnerHandler().setOwner(owner);
cocoon.setNursery(nursery);
cocoon.setAge(age);
@@ -14,9 +14,11 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.OwnerHandler;
import net.minecraft.block.Block;
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.network.NetworkManager;
@@ -25,8 +27,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.IButterfly;
@@ -34,7 +34,6 @@ import forestry.api.lepidopterology.IButterflyCocoon;
import forestry.api.lepidopterology.IButterflyGenome;
import forestry.api.lepidopterology.IButterflyNursery;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.core.access.IOwnable;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
@@ -43,16 +42,15 @@ import forestry.core.proxy.Proxies;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.NBTUtilForestry;
import forestry.core.utils.PlayerUtil;
import forestry.greenhouse.multiblock.GreenhouseController;
import forestry.lepidopterology.genetics.Butterfly;
import forestry.lepidopterology.genetics.ButterflyDefinition;
public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IButterflyCocoon {
public class TileCocoon extends TileEntity implements IStreamable, IOwnedTile, IButterflyCocoon {
private final OwnerHandler ownerHandler = new OwnerHandler();
private int age;
private int maturationTime;
private IButterfly caterpillar = ButterflyDefinition.CabbageWhite.getIndividual();
private GameProfile owner;
private BlockPos nursery;
private boolean isSolid;
@@ -74,9 +72,7 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
if (nbttagcompound.hasKey("Caterpillar")) {
caterpillar = new Butterfly(nbttagcompound.getCompoundTag("Caterpillar"));
}
if (nbttagcompound.hasKey("owner")) {
owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"));
}
ownerHandler.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("nursery")) {
NBTTagCompound nbt = nbttagcompound.getCompoundTag("nursery");
int x = nbt.getInteger("x");
@@ -99,11 +95,7 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
caterpillar.writeToNBT(subcompound);
nbttagcompound.setTag("Caterpillar", subcompound);
}
if (this.owner != null) {
NBTTagCompound nbt = new NBTTagCompound();
PlayerUtil.writeGameProfile(nbt, owner);
nbttagcompound.setTag("owner", nbt);
}
ownerHandler.writeToNBT(nbttagcompound);
if (nursery != null) {
BlockPos pos = nursery;
NBTTagCompound nbt = new NBTTagCompound();
@@ -145,25 +137,9 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
return ButterflyManager.butterflyRoot.templateAsIndividual(butterflyTemplate);
}
/* IOwnable */
@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;
}
@Override
@@ -32,9 +32,7 @@ import forestry.mail.PostRegistry;
import forestry.mail.gui.ContainerMailbox;
import forestry.mail.gui.GuiMailbox;
public class TileMailbox extends TileBase implements IMailContainer {
private boolean isLinked = false;
public class TileMailbox extends TileBase {
public TileMailbox() {
super("mailbox");
@@ -61,18 +59,6 @@ public class TileMailbox extends TileBase implements IMailContainer {
}
}
/* UPDATING */
@Override
public void updateServerSide() {
if (!isLinked) {
GameProfile owner = getAccessHandler().getOwner();
if (owner != null) {
getOrCreateMailInventory(worldObj, owner);
}
isLinked = true;
}
}
/* MAIL HANDLING */
public IInventory getOrCreateMailInventory(World world, @Nonnull GameProfile playerProfile) {
if (world.isRemote) {
@@ -96,31 +82,6 @@ public class TileMailbox extends TileBase implements IMailContainer {
return result;
}
@Override
public boolean hasMail() {
GameProfile owner = getAccessHandler().getOwner();
if (owner == null) {
return false;
}
IInventory mailInventory = getOrCreateMailInventory(worldObj, owner);
for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
if (mailInventory.getStackInSlot(i) != null) {
return true;
}
}
return false;
}
// TODO: Buildcraft for 1.9
// @Optional.Method(modid = "BuildCraftAPI|statements")
// @Override
// public Collection<ITriggerExternal> getExternalTriggers(EnumFacing side, TileEntity tile) {
// LinkedList<ITriggerExternal> res = new LinkedList<>();
// res.add(MailTriggers.triggerHasMail);
// return res;
// }
@Override
public Object getGui(EntityPlayer player, int data) {
return new GuiMailbox(player.inventory, this);
@@ -13,6 +13,9 @@ package forestry.mail.tiles;
import javax.annotation.Nonnull;
import java.io.IOException;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.OwnerHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
@@ -40,8 +43,8 @@ import forestry.mail.gui.GuiTrader;
import forestry.mail.inventory.InventoryTradeStation;
import forestry.mail.network.packets.PacketTraderAddressResponse;
public class TileTrader extends TileBase {
public class TileTrader extends TileBase implements IOwnedTile {
private final OwnerHandler ownerHandler = new OwnerHandler();
private IMailAddress address;
public TileTrader() {
@@ -50,6 +53,11 @@ public class TileTrader extends TileBase {
setInternalInventory(new InventoryTradeStation());
}
@Override
public IOwnerHandler getOwnerHandler() {
return ownerHandler;
}
@Override
public void openGui(EntityPlayer player, ItemStack heldItem) {
short data = (short) (isLinked() ? 0 : 1);
@@ -74,6 +82,7 @@ public class TileTrader extends TileBase {
address.writeToNBT(nbt);
nbttagcompound.setTag("address", nbt);
}
ownerHandler.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@@ -84,6 +93,7 @@ public class TileTrader extends TileBase {
if (nbttagcompound.hasKey("address")) {
address = new MailAddress(nbttagcompound.getCompoundTag("address"));
}
ownerHandler.readFromNBT(nbttagcompound);
}
/* NETWORK */
@@ -91,22 +101,24 @@ public class TileTrader extends TileBase {
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
String name = null;
ownerHandler.writeData(data);
String addressName = null;
if (address != null) {
name = address.getName();
addressName = address.getName();
}
if (name == null) {
name = "";
if (addressName == null) {
addressName = "";
}
data.writeUTF(name);
data.writeUTF(addressName);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
String address = data.readUTF();
if (!address.isEmpty()) {
this.address = PostManager.postRegistry.getMailAddress(address);
ownerHandler.readData(data);
String addressName = data.readUTF();
if (!addressName.isEmpty()) {
address = PostManager.postRegistry.getMailAddress(addressName);
}
}
@@ -289,7 +301,7 @@ public class TileTrader extends TileBase {
if (hasValidTradeAddress & hasUniqueTradeAddress) {
this.address = address;
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getAccessHandler().getOwner(), address);
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerHandler().getOwner(), address);
}
} else {
this.address = address;
@@ -303,7 +315,7 @@ public class TileTrader extends TileBase {
return super.getInternalInventory();
}
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getAccessHandler().getOwner(), address);
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerHandler().getOwner(), address);
}
// TODO: Buildcraft for 1.9
@@ -141,8 +141,8 @@ public class PluginIC2 extends BlankForestryPlugin {
Circuit.energyElectricBoost1 = new CircuitElectricBoost("electric.boost.1", 2, 7, 20);
Circuit.energyElectricBoost2 = new CircuitElectricBoost("electric.boost.2", 2, 15, 40);
blocks.electricalEngine.init();
blocks.generator.init();
blocks.electricalEngine.init();
blocks.generator.init();
}
@Override
@@ -154,19 +154,20 @@ public class PluginIC2 extends BlankForestryPlugin {
}
IBackpackDefinition forester = BackpackManager.backpackInterface.getBackpack(BackpackManager.FORESTER_UID);
if (resin != null) {
forester.addValidItem(resin);
}
if (rubber != null) {
forester.addValidItem(rubber);
}
if (rubberSapling != null) {
forester.addValidItem(rubberSapling);
}
ItemStack rubberLeaves = IC2Items.getItem("leaves");
if (rubberLeaves != null) {
forester.addValidItem(rubberLeaves);
if (forester != null) {
if (resin != null) {
forester.addValidItem(resin);
}
if (rubber != null) {
forester.addValidItem(rubber);
}
if (rubberSapling != null) {
forester.addValidItem(rubberSapling);
}
ItemStack rubberLeaves = IC2Items.getItem("leaves");
if (rubberLeaves != null) {
forester.addValidItem(rubberLeaves);
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 B