mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-13 17:04:15 +00:00
Finished controller slave implementation.
This commit is contained in:
1 parent
4cd0bfe33e
commit
4983712824
6 files changed
+129
-17
No files matched your search
@@ -54,6 +54,7 @@ tile.halfDrawers4.big_oak.name=Compact Dark Oak Drawers 2x2
|
||||
|
||||
tile.compDrawers.name=Compacting Drawer
|
||||
tile.drawerController.name=Drawer Controller
|
||||
tile.controllerSlave.name=Controller Slave
|
||||
|
||||
tile.trim.oak.name=Oak Trim
|
||||
tile.trim.spruce.name=Spruce Trim
|
||||
@@ -90,6 +91,7 @@ storageDrawers.config.blocks.halfDrawers4=Compact Drawers 2x2
|
||||
storageDrawers.config.blocks.compDrawers=Compacting Drawer
|
||||
storageDrawers.config.blocks.controller=Drawer Controller
|
||||
storageDrawers.config.blocks.trim=Trim
|
||||
storageDrawers.config.blocks.controllerSlave=Controller Slave
|
||||
|
||||
storageDrawers.config.upgrades=Upgrade Settings
|
||||
storageDrawers.config.upgrades.tooltip=Configure individual storage upgrades.
|
||||
|
||||
@@ -48,6 +48,10 @@ public class BlockSlave extends BlockContainer implements INetworked
|
||||
return new TileEntitySlave();
|
||||
}
|
||||
|
||||
public void bindController (World world, int x, int y, int z) {
|
||||
TileEntitySlave te = getTileEntitySafe(world, x, y, z);
|
||||
}
|
||||
|
||||
public TileEntitySlave getTileEntity (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntity tile = blockAccess.getTileEntity(x, y, z);
|
||||
return (tile instanceof TileEntitySlave) ? (TileEntitySlave) tile : null;
|
||||
@@ -58,6 +62,7 @@ public class BlockSlave extends BlockContainer implements INetworked
|
||||
if (tile == null) {
|
||||
tile = createNewTileEntity(world, world.getBlockMetadata(x, y, z));
|
||||
world.setTileEntity(x, y, z, tile);
|
||||
tile.ensureInitialized();
|
||||
}
|
||||
|
||||
return tile;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroupInteractive;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockSlave;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -125,8 +126,12 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
updateCache();
|
||||
}
|
||||
|
||||
public boolean isValidSlave (int x, int y, int z) {
|
||||
return false;
|
||||
public boolean isValidSlave (BlockCoord coord) {
|
||||
StorageRecord record = storage.get(coord);
|
||||
if (record == null || !record.mark)
|
||||
return false;
|
||||
|
||||
return record.storage == null;
|
||||
}
|
||||
|
||||
public void updateCache () {
|
||||
@@ -217,7 +222,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
}
|
||||
|
||||
private void updateRecordInfo (BlockCoord coord, StorageRecord record, TileEntity te) {
|
||||
if (te == null || !(te instanceof IDrawerGroup)) {
|
||||
if (te == null) {
|
||||
if (record.storage != null)
|
||||
clearRecordInfo(coord, record);
|
||||
|
||||
@@ -237,7 +242,21 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
invBlockList.add(null);
|
||||
invSlotList.add(0);
|
||||
}
|
||||
else {
|
||||
else if (te instanceof TileEntitySlave) {
|
||||
if (record.storage == null && record.invStorageSize == 0) {
|
||||
if (((TileEntitySlave) te).getController() == this)
|
||||
return;
|
||||
}
|
||||
|
||||
if (record.storage != null)
|
||||
clearRecordInfo(coord, record);
|
||||
|
||||
record.storage = null;
|
||||
record.invStorageSize = 0;
|
||||
|
||||
((TileEntitySlave) te).bindController(xCoord, yCoord, zCoord);
|
||||
}
|
||||
else if (te instanceof IDrawerGroup) {
|
||||
IDrawerGroup group = (IDrawerGroup)te;
|
||||
if (record.storage == group)
|
||||
return;
|
||||
@@ -265,6 +284,10 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
|
||||
drawerSize += record.drawerStorageSize;
|
||||
}
|
||||
else {
|
||||
if (record.storage != null)
|
||||
clearRecordInfo(coord, record);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateNode (int x, int y, int z, int depth) {
|
||||
@@ -282,6 +305,10 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
storage.put(coord, record);
|
||||
}
|
||||
|
||||
if (block instanceof BlockSlave) {
|
||||
((BlockSlave) block).getTileEntitySafe(worldObj, x, y, z);
|
||||
}
|
||||
|
||||
updateRecordInfo(coord, record, worldObj.getTileEntity(x, y, z));
|
||||
record.mark = true;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -10,17 +13,26 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
public class TileEntitySlave extends TileEntity implements IDrawerGroup, ISidedInventory
|
||||
{
|
||||
private BlockCoord controllerCoord;
|
||||
private BlockCoord selfCoord;
|
||||
|
||||
private int[] inventorySlots = new int[] { 0 };
|
||||
private int[] autoSides = new int[] { 0, 1, 2, 3, 4, 5 };
|
||||
|
||||
public void ensureInitialized () {
|
||||
if (selfCoord == null) {
|
||||
selfCoord = new BlockCoord(xCoord, yCoord, zCoord);
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
selfCoord = new BlockCoord(xCoord, yCoord, zCoord);
|
||||
|
||||
if (tag.hasKey("Controller", Constants.NBT.TAG_COMPOUND)) {
|
||||
NBTTagCompound ctag = tag.getCompoundTag("Controller");
|
||||
controllerCoord = new BlockCoord(ctag.getInteger("x"), ctag.getInteger("y"), ctag.getInteger("z"));
|
||||
@@ -54,7 +66,15 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
|
||||
}
|
||||
|
||||
private TileEntityController getController () {
|
||||
public void bindController (int x, int y, int z) {
|
||||
if (controllerCoord != null && controllerCoord.x() == x && controllerCoord.y() == y && controllerCoord.z() == z)
|
||||
return;
|
||||
|
||||
controllerCoord = new BlockCoord(x, y, z);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public TileEntityController getController () {
|
||||
if (controllerCoord == null)
|
||||
return null;
|
||||
|
||||
@@ -71,7 +91,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return inventorySlots;
|
||||
|
||||
return controller.getAccessibleSlotsFromSide(0);
|
||||
@@ -80,7 +100,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack stack, int side) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return false;
|
||||
|
||||
return controller.canInsertItem(slot, stack, 0);
|
||||
@@ -89,7 +109,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack stack, int side) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return false;
|
||||
|
||||
return controller.canExtractItem(slot, stack, side);
|
||||
@@ -98,7 +118,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return 1;
|
||||
|
||||
return controller.getSizeInventory();
|
||||
@@ -107,7 +127,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return null;
|
||||
|
||||
return controller.getStackInSlot(slot);
|
||||
@@ -116,7 +136,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return null;
|
||||
|
||||
return controller.decrStackSize(slot, count);
|
||||
@@ -125,7 +145,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return null;
|
||||
|
||||
return controller.getStackInSlotOnClosing(slot);
|
||||
@@ -134,7 +154,7 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack stack) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return;
|
||||
|
||||
controller.setInventorySlotContents(slot, stack);
|
||||
@@ -175,9 +195,63 @@ public class TileEntitySlave extends TileEntity implements ISidedInventory
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int slot, ItemStack stack) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return false;
|
||||
|
||||
return controller.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDrawerCount () {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return 0;
|
||||
|
||||
return controller.getDrawerCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDrawer getDrawer (int slot) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return null;
|
||||
|
||||
return controller.getDrawer(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawerEnabled (int slot) {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return false;
|
||||
|
||||
return controller.isDrawerEnabled(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDrawerInventory getDrawerInventory () {
|
||||
TileEntityController controller = getController();
|
||||
if (controller == null || !controller.isValidSlave(selfCoord))
|
||||
return null;
|
||||
|
||||
return controller.getDrawerInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
TileEntityController controller = getController();
|
||||
if (controller != null && controller.isValidSlave(selfCoord))
|
||||
controller.markDirty();
|
||||
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markDirtyIfNeeded () {
|
||||
TileEntityController controller = getController();
|
||||
if (controller != null && controller.isValidSlave(selfCoord))
|
||||
return controller.markDirtyIfNeeded();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,10 @@ public class ModRecipes
|
||||
GameRegistry.addRecipe(new ItemStack(ModBlocks.controller), "xxx", "yzy", "xwx",
|
||||
'x', new ItemStack(Blocks.stone), 'y', Items.comparator, 'z', new ItemStack(ModBlocks.fullDrawers2, 1, OreDictionary.WILDCARD_VALUE), 'w', Items.diamond);
|
||||
|
||||
if (config.isBlockEnabled("controllerSlave"))
|
||||
GameRegistry.addRecipe(new ItemStack(ModBlocks.controllerSlave), "xxx", "yzy", "xwx",
|
||||
'x', new ItemStack(Blocks.stone), 'y', Items.comparator, 'z', new ItemStack(ModBlocks.fullDrawers2, 1, OreDictionary.WILDCARD_VALUE), 'w', Items.gold_ingot);
|
||||
|
||||
if (config.isBlockEnabled("fulldrawers1"))
|
||||
GameRegistry.addRecipe(new ItemStack(ModItems.upgradeTemplate, 2), "xxx", "xyx", "xxx",
|
||||
'x', Items.stick, 'y', new ItemStack(ModBlocks.fullDrawers1, 1, OreDictionary.WILDCARD_VALUE));
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ItemUpgradeLock extends Item
|
||||
@Override
|
||||
public Multimap getAttributeModifiers (ItemStack item) {
|
||||
Multimap multimap = super.getAttributeModifiers(item);
|
||||
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)1, 0));
|
||||
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)2, 0));
|
||||
return multimap;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user