diff --git a/lang b/lang index 2d88011e4..82c5455d7 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 2d88011e4a303294900cfbdb2c2522c54ca4b069 +Subproject commit 82c5455d7ba9852508aa36c4d3fa1269704d872f diff --git a/src/main/java/forestry/apiculture/InventoryBeeHousing.java b/src/main/java/forestry/apiculture/InventoryBeeHousing.java index 8baa3e0db..203e7af1b 100644 --- a/src/main/java/forestry/apiculture/InventoryBeeHousing.java +++ b/src/main/java/forestry/apiculture/InventoryBeeHousing.java @@ -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 diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java b/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java index 49358dade..ab30aa4d8 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java @@ -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) { diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java index 903dd6d7e..0a0ca7dad 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java @@ -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> 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 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); } } diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java index 7977e3b93..4395df345 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java @@ -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) { diff --git a/src/main/java/forestry/apiculture/inventory/InventoryApiary.java b/src/main/java/forestry/apiculture/inventory/InventoryApiary.java index ee0113beb..a06601eb2 100644 --- a/src/main/java/forestry/apiculture/inventory/InventoryApiary.java +++ b/src/main/java/forestry/apiculture/inventory/InventoryApiary.java @@ -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 diff --git a/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java b/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java index 268cf5b19..a46564a38 100644 --- a/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java +++ b/src/main/java/forestry/apiculture/items/ItemMinecartBeehouse.java @@ -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()); diff --git a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java index 687439b92..cbcd6aa4a 100644 --- a/src/main/java/forestry/apiculture/multiblock/AlvearyController.java +++ b/src/main/java/forestry/apiculture/multiblock/AlvearyController.java @@ -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 diff --git a/src/main/java/forestry/apiculture/multiblock/IAlvearyControllerInternal.java b/src/main/java/forestry/apiculture/multiblock/IAlvearyControllerInternal.java index f944bfcb3..2753518a1 100644 --- a/src/main/java/forestry/apiculture/multiblock/IAlvearyControllerInternal.java +++ b/src/main/java/forestry/apiculture/multiblock/IAlvearyControllerInternal.java @@ -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); diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java index 9b2864ede..62dd14574 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java @@ -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 implements IBeeHousing, IAlvearyComponent, IRestrictedAccess, IStreamableGui, ITitled, IClimatised, IHintSource { +public abstract class TileAlveary extends MultiblockTileEntityForestry implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimatised, IHintSource { private final String unlocalizedTitle; protected TileAlveary() { @@ -143,13 +142,8 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry= 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(); diff --git a/src/main/java/forestry/arboriculture/tiles/TileSapling.java b/src/main/java/forestry/arboriculture/tiles/TileSapling.java index 6d097c48b..f246e7c77 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileSapling.java +++ b/src/main/java/forestry/arboriculture/tiles/TileSapling.java @@ -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); } } diff --git a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java index 948292aaf..2bfabe5d2 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java +++ b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java @@ -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 */ diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java index ff4884478..fd9a109b0 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java @@ -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) { diff --git a/src/main/java/forestry/core/PluginCore.java b/src/main/java/forestry/core/PluginCore.java index 04c1c6d2d..f2ffb4869 100644 --- a/src/main/java/forestry/core/PluginCore.java +++ b/src/main/java/forestry/core/PluginCore.java @@ -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()); diff --git a/src/main/java/forestry/core/access/AccessHandler.java b/src/main/java/forestry/core/access/AccessHandler.java deleted file mode 100644 index c7c114702..000000000 --- a/src/main/java/forestry/core/access/AccessHandler.java +++ /dev/null @@ -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 accessOwnerListeners = new ArrayList<>(); - private final Object target; - - private GameProfile owner = null; - private EnumAccess access = EnumAccess.SHARED; - - public AccessHandler(T tile) { - this.accessListener = tile; - this.target = tile; - } - - public 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; - } -} diff --git a/src/main/java/forestry/core/access/EnumAccess.java b/src/main/java/forestry/core/access/EnumAccess.java deleted file mode 100644 index b828c3245..000000000 --- a/src/main/java/forestry/core/access/EnumAccess.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/forestry/core/access/FakeAccessHandler.java b/src/main/java/forestry/core/access/FakeAccessHandler.java deleted file mode 100644 index 57470ae58..000000000 --- a/src/main/java/forestry/core/access/FakeAccessHandler.java +++ /dev/null @@ -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 { - - } -} diff --git a/src/main/java/forestry/core/access/IAccessHandler.java b/src/main/java/forestry/core/access/IAccessHandler.java deleted file mode 100644 index 3e4966433..000000000 --- a/src/main/java/forestry/core/access/IAccessHandler.java +++ /dev/null @@ -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); - -} diff --git a/src/main/java/forestry/core/access/IRestrictedAccess.java b/src/main/java/forestry/core/access/IRestrictedAccess.java deleted file mode 100644 index c30fca22d..000000000 --- a/src/main/java/forestry/core/access/IRestrictedAccess.java +++ /dev/null @@ -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); -} diff --git a/src/main/java/forestry/core/blocks/BlockBase.java b/src/main/java/forestry/core/blocks/BlockBase.java index 97119c31c..be7bfb0c0 100644 --- a/src/main/java/forestry/core/blocks/BlockBase.java +++ b/src/main/java/forestry/core/blocks/BlockBase.java @@ -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

& 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

& 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) { diff --git a/src/main/java/forestry/core/blocks/BlockForestry.java b/src/main/java/forestry/core/blocks/BlockForestry.java index b9351e942..e4f70ddfa 100644 --- a/src/main/java/forestry/core/blocks/BlockForestry.java +++ b/src/main/java/forestry/core/blocks/BlockForestry.java @@ -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); } } diff --git a/src/main/java/forestry/core/entities/EntityMinecartForestry.java b/src/main/java/forestry/core/entities/EntityMinecartForestry.java index 36ba05206..0f3946a8f 100644 --- a/src/main/java/forestry/core/entities/EntityMinecartForestry.java +++ b/src/main/java/forestry/core/entities/EntityMinecartForestry.java @@ -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() { diff --git a/src/main/java/forestry/core/gui/ContainerEntity.java b/src/main/java/forestry/core/gui/ContainerEntity.java index 3ea60b4c9..de07830c3 100644 --- a/src/main/java/forestry/core/gui/ContainerEntity.java +++ b/src/main/java/forestry/core/gui/ContainerEntity.java @@ -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 extends ContainerForestry { protected final T entity; - private final IAccessHandler accessHandler; + private ImmutableSet 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 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 previousErrorStates; - private EnumAccess previousAccess; - @Override public void detectAndSendChanges() { super.detectAndSendChanges(); @@ -74,17 +57,5 @@ public class ContainerEntity 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; - } - } } } diff --git a/src/main/java/forestry/core/gui/ContainerTile.java b/src/main/java/forestry/core/gui/ContainerTile.java index 0d3de64b6..6d8b1561b 100644 --- a/src/main/java/forestry/core/gui/ContainerTile.java +++ b/src/main/java/forestry/core/gui/ContainerTile.java @@ -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 extends ContainerForestry { - protected final T tile; - private final IAccessHandler accessHandler; + private ImmutableSet 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 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 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 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; diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 794b1d2d3..e94855f4c 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -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 ext } } - if (inventory instanceof IRestrictedAccess) { - ledgerManager.add(new OwnerLedger(ledgerManager, (IRestrictedAccess) inventory)); + if (inventory instanceof IOwnedTile) { + ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnedTile) inventory)); } } diff --git a/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java index ea47053b7..cfb3b0688 100644 --- a/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/OwnerLedger.java @@ -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); } } diff --git a/src/main/java/forestry/core/inventory/InventoryAdapterRestricted.java b/src/main/java/forestry/core/inventory/InventoryAdapterRestricted.java index e94cd5bda..7795f87e8 100644 --- a/src/main/java/forestry/core/inventory/InventoryAdapterRestricted.java +++ b/src/main/java/forestry/core/inventory/InventoryAdapterRestricted.java @@ -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; } } diff --git a/src/main/java/forestry/core/inventory/InventoryAdapterTile.java b/src/main/java/forestry/core/inventory/InventoryAdapterTile.java index c7ffcfcc7..5cee21248 100644 --- a/src/main/java/forestry/core/inventory/InventoryAdapterTile.java +++ b/src/main/java/forestry/core/inventory/InventoryAdapterTile.java @@ -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 extends InventoryAdapterRestricted { +public class InventoryAdapterTile extends InventoryAdapterRestricted { protected final T tile; @@ -25,7 +23,7 @@ public class InventoryAdapterTile exte } public InventoryAdapterTile(T tile, int size, String name, int stackLimit) { - super(size, name, stackLimit, tile.getAccessHandler()); + super(size, name, stackLimit); this.tile = tile; } diff --git a/src/main/java/forestry/core/multiblock/FakeMultiblockController.java b/src/main/java/forestry/core/multiblock/FakeMultiblockController.java index 95fae9cdc..5d28d5998 100644 --- a/src/main/java/forestry/core/multiblock/FakeMultiblockController.java +++ b/src/main/java/forestry/core/multiblock/FakeMultiblockController.java @@ -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 diff --git a/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java b/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java index bdf77c985..c9c9d6241 100644 --- a/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java +++ b/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java @@ -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. diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java b/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java index bd8741868..5d0e723a4 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java @@ -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 */ diff --git a/src/main/java/forestry/core/network/PacketIdClient.java b/src/main/java/forestry/core/network/PacketIdClient.java index 5d4a5c159..8a62fc3e2 100644 --- a/src/main/java/forestry/core/network/PacketIdClient.java +++ b/src/main/java/forestry/core/network/PacketIdClient.java @@ -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, diff --git a/src/main/java/forestry/core/network/PacketIdServer.java b/src/main/java/forestry/core/network/PacketIdServer.java index 1f39e3f34..b9dcfd1ad 100644 --- a/src/main/java/forestry/core/network/PacketIdServer.java +++ b/src/main/java/forestry/core/network/PacketIdServer.java @@ -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, diff --git a/src/main/java/forestry/core/network/PacketRegistryCore.java b/src/main/java/forestry/core/network/PacketRegistryCore.java index 3e0da76b1..2c53b67fe 100644 --- a/src/main/java/forestry/core/network/PacketRegistryCore.java +++ b/src/main/java/forestry/core/network/PacketRegistryCore.java @@ -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()); } diff --git a/src/main/java/forestry/core/network/packets/PacketAccessSwitch.java b/src/main/java/forestry/core/network/packets/PacketAccessSwitch.java deleted file mode 100644 index 2baac01c6..000000000 --- a/src/main/java/forestry/core/network/packets/PacketAccessSwitch.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/forestry/core/network/packets/PacketAccessSwitchEntity.java b/src/main/java/forestry/core/network/packets/PacketAccessSwitchEntity.java deleted file mode 100644 index 3e04e5906..000000000 --- a/src/main/java/forestry/core/network/packets/PacketAccessSwitchEntity.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/forestry/core/network/packets/PacketAccessUpdate.java b/src/main/java/forestry/core/network/packets/PacketAccessUpdate.java deleted file mode 100644 index 49872c493..000000000 --- a/src/main/java/forestry/core/network/packets/PacketAccessUpdate.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/forestry/core/network/packets/PacketAccessUpdateEntity.java b/src/main/java/forestry/core/network/packets/PacketAccessUpdateEntity.java deleted file mode 100644 index 4b458e0f3..000000000 --- a/src/main/java/forestry/core/network/packets/PacketAccessUpdateEntity.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/forestry/core/access/IAccessOwnerListener.java b/src/main/java/forestry/core/owner/FakeOwnerHandler.java similarity index 57% rename from src/main/java/forestry/core/access/IAccessOwnerListener.java rename to src/main/java/forestry/core/owner/FakeOwnerHandler.java index cdd0ec89d..979e5f63b 100644 --- a/src/main/java/forestry/core/access/IAccessOwnerListener.java +++ b/src/main/java/forestry/core/owner/FakeOwnerHandler.java @@ -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) { + + } +} diff --git a/src/main/java/forestry/core/owner/GameProfileDataSerializer.java b/src/main/java/forestry/core/owner/GameProfileDataSerializer.java new file mode 100644 index 000000000..267c8723f --- /dev/null +++ b/src/main/java/forestry/core/owner/GameProfileDataSerializer.java @@ -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> { + public static final GameProfileDataSerializer INSTANCE = new GameProfileDataSerializer(); + + public static void register() { + DataSerializers.registerSerializer(INSTANCE); + } + + private GameProfileDataSerializer() { + + } + + @Override + public void write(PacketBuffer buf, Optional 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 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> createKey(int id) { + return new DataParameter<>(id, this); + } +} diff --git a/src/main/java/forestry/mail/tiles/IMailContainer.java b/src/main/java/forestry/core/owner/IOwnedTile.java similarity index 86% rename from src/main/java/forestry/mail/tiles/IMailContainer.java rename to src/main/java/forestry/core/owner/IOwnedTile.java index a99fa9159..7e8cc74aa 100644 --- a/src/main/java/forestry/mail/tiles/IMailContainer.java +++ b/src/main/java/forestry/core/owner/IOwnedTile.java @@ -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(); } diff --git a/src/main/java/forestry/core/access/IOwnable.java b/src/main/java/forestry/core/owner/IOwnerHandler.java similarity index 81% rename from src/main/java/forestry/core/access/IOwnable.java rename to src/main/java/forestry/core/owner/IOwnerHandler.java index 308f0095c..051513413 100644 --- a/src/main/java/forestry/core/access/IOwnable.java +++ b/src/main/java/forestry/core/owner/IOwnerHandler.java @@ -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); - } diff --git a/src/main/java/forestry/core/owner/OwnerHandler.java b/src/main/java/forestry/core/owner/OwnerHandler.java new file mode 100644 index 000000000..88da89d93 --- /dev/null +++ b/src/main/java/forestry/core/owner/OwnerHandler.java @@ -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; + } +} diff --git a/src/main/java/forestry/core/proxy/ProxyClient.java b/src/main/java/forestry/core/proxy/ProxyClient.java index 24caa7a99..6d3e77069 100644 --- a/src/main/java/forestry/core/proxy/ProxyClient.java +++ b/src/main/java/forestry/core/proxy/ProxyClient.java @@ -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) { diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 28eae0dfa..67071e4a3 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -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 != null && userlistopsentry.getPermissionLevel() >= server.getOpPermissionLevel(); - } - public double getBlockReachDistance(EntityPlayer entityplayer) { return 4f; } diff --git a/src/main/java/forestry/core/tiles/TileForestry.java b/src/main/java/forestry/core/tiles/TileForestry.java index 09a5fe461..bf7476705 100644 --- a/src/main/java/forestry/core/tiles/TileForestry.java +++ b/src/main/java/forestry/core/tiles/TileForestry.java @@ -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 */ /** diff --git a/src/main/java/forestry/core/utils/InventoryUtil.java b/src/main/java/forestry/core/utils/InventoryUtil.java index f40edc98f..50d687ed4 100644 --- a/src/main/java/forestry/core/utils/InventoryUtil.java +++ b/src/main/java/forestry/core/utils/InventoryUtil.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.utils; +import javax.annotation.Nullable; import java.util.Collection; import net.minecraft.entity.item.EntityItem; @@ -197,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) { @@ -208,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); @@ -238,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) { @@ -487,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; } diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java index 25a1265e4..1f3eb3b7d 100644 --- a/src/main/java/forestry/core/utils/PlayerUtil.java +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -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 { diff --git a/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java b/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java index b2d2bc697..8c9a210fa 100644 --- a/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java +++ b/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java @@ -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 extends InventoryAdapterTile { +public class InventoryGhostCrafting extends InventoryAdapterTile { public final static int SLOT_CRAFTING_1 = 0; public final static int SLOT_CRAFTING_COUNT = 9; public final static int SLOT_CRAFTING_RESULT = 9; diff --git a/src/main/java/forestry/factory/inventory/InventorySqueezer.java b/src/main/java/forestry/factory/inventory/InventorySqueezer.java index 076ef29b2..4e74a7e08 100644 --- a/src/main/java/forestry/factory/inventory/InventorySqueezer.java +++ b/src/main/java/forestry/factory/inventory/InventorySqueezer.java @@ -69,9 +69,9 @@ public class InventorySqueezer extends InventoryAdapterTile { 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) { diff --git a/src/main/java/forestry/factory/tiles/TileCarpenter.java b/src/main/java/forestry/factory/tiles/TileCarpenter.java index 94fc19c97..9d304e9e4 100644 --- a/src/main/java/forestry/factory/tiles/TileCarpenter.java +++ b/src/main/java/forestry/factory/tiles/TileCarpenter.java @@ -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 */ diff --git a/src/main/java/forestry/factory/tiles/TileSqueezer.java b/src/main/java/forestry/factory/tiles/TileSqueezer.java index 14175ded3..65ffae61f 100644 --- a/src/main/java/forestry/factory/tiles/TileSqueezer.java +++ b/src/main/java/forestry/factory/tiles/TileSqueezer.java @@ -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; } diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index 6a72607e8..1017cbe93 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -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); } diff --git a/src/main/java/forestry/farming/multiblock/IFarmControllerInternal.java b/src/main/java/forestry/farming/multiblock/IFarmControllerInternal.java index 36d6e2abc..ffa9720c9 100644 --- a/src/main/java/forestry/farming/multiblock/IFarmControllerInternal.java +++ b/src/main/java/forestry/farming/multiblock/IFarmControllerInternal.java @@ -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(); diff --git a/src/main/java/forestry/farming/multiblock/InventoryFarm.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java index c156fa9ed..4945285de 100644 --- a/src/main/java/forestry/farming/multiblock/InventoryFarm.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -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); } diff --git a/src/main/java/forestry/farming/tiles/TileFarm.java b/src/main/java/forestry/farming/tiles/TileFarm.java index 53067a1e1..e9f0aa17e 100644 --- a/src/main/java/forestry/farming/tiles/TileFarm.java +++ b/src/main/java/forestry/farming/tiles/TileFarm.java @@ -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 implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IRestrictedAccess, ITitled { +public abstract class TileFarm extends MultiblockTileEntityForestry implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled { private EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.BRICK_STONE; @@ -166,13 +165,8 @@ public abstract class TileFarm extends MultiblockTileEntityForestry implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IRestrictedAccess, ITitled, ICamouflageHandler, ICamouflagedTile { +public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile { private ItemStack camouflageBlock; @@ -172,13 +171,8 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent.Door, IErrorLogicSource, IRestrictedAccess { +public class TileGreenhouseDoor extends MultiblockTileEntityForestry implements IGreenhouseComponent.Door, IErrorLogicSource, IOwnedTile { public TileGreenhouseDoor() { super(new MultiblockLogicGreenhouse()); @@ -47,13 +45,8 @@ public class TileGreenhouseDoor extends MultiblockTileEntityForestry implements IGreenhouseComponent, IHintSource, IErrorLogicSource, IRestrictedAccess, ICamouflageHandler, ICamouflagedTile, IFluidHandler, IEnergyProvider, IEnergyReceiver { +public class TileGreenhouseHatch extends MultiblockTileEntityBase implements IGreenhouseComponent, IHintSource, IErrorLogicSource, IOwnedTile, ICamouflageHandler, ICamouflagedTile, IFluidHandler, IEnergyProvider, IEnergyReceiver { EnumFacing outwards; private ItemStack camouflageBlock; @@ -197,13 +196,8 @@ public class TileGreenhouseHatch extends MultiblockTileEntityBase getExternalTriggers(EnumFacing side, TileEntity tile) { -// LinkedList res = new LinkedList<>(); -// res.add(MailTriggers.triggerHasMail); -// return res; -// } - @Override public Object getGui(EntityPlayer player, int data) { return new GuiMailbox(player.inventory, this); diff --git a/src/main/java/forestry/mail/tiles/TileTrader.java b/src/main/java/forestry/mail/tiles/TileTrader.java index 516fb947f..730209add 100644 --- a/src/main/java/forestry/mail/tiles/TileTrader.java +++ b/src/main/java/forestry/mail/tiles/TileTrader.java @@ -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 diff --git a/src/main/resources/assets/forestry/textures/gui/misc/access.private.png b/src/main/resources/assets/forestry/textures/gui/misc/access.private.png deleted file mode 100644 index a45439775..000000000 Binary files a/src/main/resources/assets/forestry/textures/gui/misc/access.private.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/gui/misc/access.viewable.png b/src/main/resources/assets/forestry/textures/gui/misc/access.viewable.png deleted file mode 100644 index 9321ab684..000000000 Binary files a/src/main/resources/assets/forestry/textures/gui/misc/access.viewable.png and /dev/null differ