Most of the controller slave implementation.

This commit is contained in:
Justin Aquadro committed 2015-04-25 03:10:14 -04:00
1 parent 49ea5b4f0c
commit 4cd0bfe33e
6 files changed
+320 -37

No files matched your search

@@ -0,0 +1,72 @@
package com.jaquadro.minecraft.storagedrawers.block;
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntitySlave;
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockSlave extends BlockContainer implements INetworked
{
@SideOnly(Side.CLIENT)
private IIcon iconSide;
@SideOnly(Side.CLIENT)
private IIcon iconSideEtched;
public BlockSlave (String blockName) {
super(Material.rock);
setCreativeTab(ModCreativeTabs.tabStorageDrawers);
setHardness(5f);
setBlockName(blockName);
setStepSound(Block.soundTypeStone);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta) {
switch (side) {
case 0:
case 1:
return iconSide;
default:
return iconSideEtched;
}
}
@Override
public TileEntitySlave createNewTileEntity (World world, int meta) {
return new TileEntitySlave();
}
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;
}
public TileEntitySlave getTileEntitySafe (World world, int x, int y, int z) {
TileEntitySlave tile = getTileEntity(world, x, y, z);
if (tile == null) {
tile = createNewTileEntity(world, world.getBlockMetadata(x, y, z));
world.setTileEntity(x, y, z, tile);
}
return tile;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons (IIconRegister register) {
iconSide = register.registerIcon(StorageDrawers.MOD_ID + ":drawers_comp_side");
iconSideEtched = register.registerIcon(StorageDrawers.MOD_ID + ":drawers_comp_side_2");
}
}
@@ -0,0 +1,48 @@
package com.jaquadro.minecraft.storagedrawers.block.tile;
/**
* Created by Justin on 4/25/2015.
*/
class BlockCoord
{
private int x;
private int y;
private int z;
public BlockCoord (int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int x () {
return x;
}
public int y () {
return y;
}
public int z () {
return z;
}
@Override
public boolean equals (Object obj) {
if (obj == null || obj.getClass() != getClass())
return false;
BlockCoord that = (BlockCoord)obj;
return x == that.x && y == that.y && z == that.z;
}
@Override
public int hashCode () {
int hash = 23;
hash = hash * 31 + x;
hash = hash * 31 + y;
hash = hash * 31 + z;
return hash;
}
}
@@ -23,37 +23,6 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
private static final int DEPTH_LIMIT = 12;
private static final int[] emptySlots = new int[0];
private static class BlockCoord {
private int x;
private int y;
private int z;
public BlockCoord (int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean equals (Object obj) {
if (obj == null || obj.getClass() != getClass())
return false;
BlockCoord that = (BlockCoord)obj;
return x == that.x && y == that.y && z == that.z;
}
@Override
public int hashCode () {
int hash = 23;
hash = hash * 31 + x;
hash = hash * 31 + y;
hash = hash * 31 + z;
return hash;
}
}
private static class StorageRecord
{
public IDrawerGroup storage;
@@ -156,6 +125,10 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
updateCache();
}
public boolean isValidSlave (int x, int y, int z) {
return false;
}
public void updateCache () {
int preCount = inventorySlots.length;
@@ -339,7 +312,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
if (!storage.containsKey(coord))
return null;
TileEntity te = worldObj.getTileEntity(coord.x, coord.y, coord.z);
TileEntity te = worldObj.getTileEntity(coord.x(), coord.y(), coord.z());
if (!(te instanceof IDrawerGroup)) {
storage.remove(coord);
return null;
@@ -359,7 +332,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
if (!storage.containsKey(coord))
return null;
TileEntity te = worldObj.getTileEntity(coord.x, coord.y, coord.z);
TileEntity te = worldObj.getTileEntity(coord.x(), coord.y(), coord.z());
if (!(te instanceof IDrawerGroup)) {
storage.remove(coord);
return null;
@@ -0,0 +1,183 @@
package com.jaquadro.minecraft.storagedrawers.block.tile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
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
{
private BlockCoord controllerCoord;
private int[] inventorySlots = new int[] { 0 };
private int[] autoSides = new int[] { 0, 1, 2, 3, 4, 5 };
@Override
public void readFromNBT (NBTTagCompound tag) {
super.readFromNBT(tag);
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"));
}
}
@Override
public void writeToNBT (NBTTagCompound tag) {
super.writeToNBT(tag);
if (controllerCoord != null) {
NBTTagCompound ctag = new NBTTagCompound();
ctag.setInteger("x", controllerCoord.x());
ctag.setInteger("y", controllerCoord.y());
ctag.setInteger("z", controllerCoord.z());
tag.setTag("Controller", ctag);
}
}
@Override
public Packet getDescriptionPacket () {
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 5, tag);
}
@Override
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
}
private TileEntityController getController () {
if (controllerCoord == null)
return null;
TileEntity te = worldObj.getTileEntity(controllerCoord.x(), controllerCoord.y(), controllerCoord.z());
if (!(te instanceof TileEntityController)) {
controllerCoord = null;
markDirty();
return null;
}
return (TileEntityController)te;
}
@Override
public int[] getAccessibleSlotsFromSide (int side) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return inventorySlots;
return controller.getAccessibleSlotsFromSide(0);
}
@Override
public boolean canInsertItem (int slot, ItemStack stack, int side) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return false;
return controller.canInsertItem(slot, stack, 0);
}
@Override
public boolean canExtractItem (int slot, ItemStack stack, int side) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return false;
return controller.canExtractItem(slot, stack, side);
}
@Override
public int getSizeInventory () {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return 1;
return controller.getSizeInventory();
}
@Override
public ItemStack getStackInSlot (int slot) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return null;
return controller.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize (int slot, int count) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return null;
return controller.decrStackSize(slot, count);
}
@Override
public ItemStack getStackInSlotOnClosing (int slot) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return null;
return controller.getStackInSlotOnClosing(slot);
}
@Override
public void setInventorySlotContents (int slot, ItemStack stack) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return;
controller.setInventorySlotContents(slot, stack);
}
@Override
public String getInventoryName () {
// TODO
return null;
}
@Override
public boolean hasCustomInventoryName () {
// TODO
return false;
}
@Override
public int getInventoryStackLimit () {
return 64;
}
@Override
public boolean isUseableByPlayer (EntityPlayer player) {
return false;
}
@Override
public void openInventory () {
}
@Override
public void closeInventory () {
}
@Override
public boolean isItemValidForSlot (int slot, ItemStack stack) {
TileEntityController controller = getController();
if (controller == null || !controller.isValidSlave(xCoord, yCoord, zCoord))
return false;
return controller.isItemValidForSlot(slot, stack);
}
}
@@ -93,6 +93,7 @@ public class ConfigManager
public final ConfigSection sectionBlocksCompDrawers = new ConfigSection(blockSections, sectionBlocks, "compdrawers", "blocks.compDrawers");
public final ConfigSection sectionBlocksController = new ConfigSection(blockSections, sectionBlocks, "controller", "blocks.controller");
public final ConfigSection sectionBlocksTrim = new ConfigSection(blockSections, sectionBlocks, "trim", "blocks.trim");
public final ConfigSection sectionBlocksSlave = new ConfigSection(blockSections, sectionBlocks, "controllerSlave", "blocks.controllerSlave");
public Map<String, ConfigSection> blockSectionsMap = new HashMap<String, ConfigSection>();
@@ -164,6 +165,8 @@ public class ConfigManager
config.get(sectionBlocksTrim.getQualifiedName(), "enabled", true).setLanguageKey(LANG_PREFIX + "prop.enabled").setRequiresMcRestart(true);
config.get(sectionBlocksSlave.getQualifiedName(), "enabled", true).setLanguageKey(LANG_PREFIX + "prop.enabled").setRequiresMcRestart(true);
cache.level2Mult = config.get(sectionUpgrades.getQualifiedName(), "level2Mult", 2).setLanguageKey(LANG_PREFIX + "upgrades.level2Mult").setRequiresWorldRestart(true).getInt();
cache.level3Mult = config.get(sectionUpgrades.getQualifiedName(), "level3Mult", 3).setLanguageKey(LANG_PREFIX + "upgrades.level3Mult").setRequiresWorldRestart(true).getInt();
cache.level4Mult = config.get(sectionUpgrades.getQualifiedName(), "level4Mult", 5).setLanguageKey(LANG_PREFIX + "upgrades.level4Mult").setRequiresWorldRestart(true).getInt();
@@ -1,13 +1,11 @@
package com.jaquadro.minecraft.storagedrawers.core;
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
import com.jaquadro.minecraft.storagedrawers.block.BlockCompDrawers;
import com.jaquadro.minecraft.storagedrawers.block.BlockController;
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
import com.jaquadro.minecraft.storagedrawers.block.BlockTrim;
import com.jaquadro.minecraft.storagedrawers.block.*;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityController;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntitySlave;
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
import com.jaquadro.minecraft.storagedrawers.item.ItemCompDrawers;
import com.jaquadro.minecraft.storagedrawers.item.ItemController;
@@ -27,6 +25,7 @@ public class ModBlocks
public static BlockCompDrawers compDrawers;
public static BlockController controller;
public static BlockTrim trim;
public static BlockSlave controllerSlave;
public void init () {
fullDrawers1 = new BlockDrawers("fullDrawers1", 1, false);
@@ -37,6 +36,7 @@ public class ModBlocks
compDrawers = new BlockCompDrawers("compDrawers");
controller = new BlockController("drawerController");
trim = new BlockTrim("trim");
controllerSlave = new BlockSlave("controllerSlave");
ConfigManager config = StorageDrawers.config;
@@ -68,6 +68,10 @@ public class ModBlocks
GameRegistry.registerBlock(controller, ItemController.class, "controller");
GameRegistry.registerTileEntity(TileEntityController.class, ModBlocks.getQualifiedName(controller));
}
if (config.isBlockEnabled("controllerSlave")) {
GameRegistry.registerBlock(controllerSlave, "controllerSlave");
GameRegistry.registerTileEntity(TileEntitySlave.class, ModBlocks.getQualifiedName(controllerSlave));
}
if (config.isBlockEnabled("trim")) {
GameRegistry.registerBlock(trim, ItemTrim.class, "trim");
}