More work turning crate classes to scala
This commit is contained in:
parent
fcce578fab
commit
4978a7b9ba
8 changed files with 213 additions and 255 deletions
|
@ -3,6 +3,7 @@ package resonantinduction.archaic.crate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -34,18 +35,18 @@ public class BlockCrate extends SpatialBlock
|
|||
{
|
||||
IIcon advanced, elite;
|
||||
|
||||
public BlockCrate(int id)
|
||||
public BlockCrate()
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
super(Material.iron);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconReg)
|
||||
{
|
||||
this.blockIcon = iconReg.registerIcon(Reference.PREFIX + "crate_wood");
|
||||
this.advanced = iconReg.registerIcon(Reference.PREFIX + "crate_iron");
|
||||
this.elite = iconReg.registerIcon(Reference.PREFIX + "crate_steel");
|
||||
this.blockIcon = iconReg.registerIcon(Reference.prefix + "crate_wood");
|
||||
this.advanced = iconReg.registerIcon(Reference.prefix + "crate_iron");
|
||||
this.elite = iconReg.registerIcon(Reference.prefix + "crate_steel");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
package resonantinduction.archaic.crate;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import resonant.lib.utility.inventory.ExternalInventory;
|
||||
|
||||
public class InventoryCrate extends ExternalInventory
|
||||
{
|
||||
public InventoryCrate(TileEntity crate)
|
||||
{
|
||||
super(crate, 512);
|
||||
}
|
||||
|
||||
/** Clones the single stack into an inventory format for automation interaction */
|
||||
public void buildInventory(ItemStack sampleStack)
|
||||
{
|
||||
this.containedItems = new ItemStack[this.getSizeInventory()];
|
||||
if (sampleStack != null && sampleStack.getItem() != null)
|
||||
{
|
||||
ItemStack baseStack = sampleStack.copy();
|
||||
int itemsLeft = baseStack.stackSize;
|
||||
|
||||
for (int slot = 0; slot < this.getContainedItems().length; slot++)
|
||||
{
|
||||
int stackL = Math.min(Math.min(itemsLeft, baseStack.getMaxStackSize()), this.getInventoryStackLimit());
|
||||
this.getContainedItems()[slot] = baseStack.copy();
|
||||
this.getContainedItems()[slot].stackSize = stackL;
|
||||
itemsLeft -= stackL;
|
||||
if (baseStack.stackSize <= 0)
|
||||
{
|
||||
baseStack = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
if (this.hostTile instanceof TileCrate)
|
||||
{
|
||||
return ((TileCrate) this.hostTile).getSlotCount();
|
||||
}
|
||||
return 512;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName()
|
||||
{
|
||||
return "inv.Crate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt.hasKey("Items"))
|
||||
{
|
||||
super.load(nbt);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package resonantinduction.archaic.crate
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import resonant.api.IInventoryProvider
|
||||
import resonant.lib.utility.inventory.ExternalInventory
|
||||
import scala.util.control.Breaks._
|
||||
|
||||
class InventoryCrate(crate: IInventoryProvider) extends ExternalInventory(crate: IInventoryProvider, 512)
|
||||
{
|
||||
|
||||
/** Clones the single stack into an inventory format for automation interaction */
|
||||
def buildInventory(sampleStack: ItemStack)
|
||||
{
|
||||
this.containedItems = new Array[ItemStack](this.getSizeInventory)
|
||||
if (sampleStack != null && sampleStack.getItem != null)
|
||||
{
|
||||
var baseStack: ItemStack = sampleStack.copy
|
||||
var itemsLeft: Int = baseStack.stackSize
|
||||
for(slot <- this.getContainedItems.length)
|
||||
{
|
||||
val stackL: Int = Math.min(Math.min(itemsLeft, baseStack.getMaxStackSize), this.getInventoryStackLimit)
|
||||
var st = baseStack.copy
|
||||
st.stackSize = stackL
|
||||
|
||||
this.setInventorySlotContents(slot, st)
|
||||
itemsLeft -= stackL
|
||||
|
||||
if (baseStack.stackSize <= 0)
|
||||
{
|
||||
baseStack = null
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def getSizeInventory: Int =
|
||||
{
|
||||
if (this.host.isInstanceOf[TileCrate])
|
||||
{
|
||||
return (this.host.asInstanceOf[TileCrate]).getSlotCount
|
||||
}
|
||||
return 512
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound)
|
||||
{
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
{
|
||||
if (nbt.hasKey("Items"))
|
||||
{
|
||||
super.load(nbt)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
package resonantinduction.archaic.crate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.world.World;
|
||||
import resonant.lib.utility.LanguageUtility;
|
||||
|
||||
public class ItemBlockCrate extends ItemBlock
|
||||
{
|
||||
public ItemBlockCrate(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return this.getUnlocalizedName() + "." + itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4)
|
||||
{
|
||||
super.addInformation(itemStack, par2EntityPlayer, list, par4);
|
||||
ItemStack containingStack = getContainingItemStack(itemStack);
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
list.add(containingStack.getDisplayName());
|
||||
list.add(LanguageUtility.getLocal("crate.tooltip.amount") + " " + containingStack.stackSize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack)
|
||||
{
|
||||
ItemStack containingStack = getContainingItemStack(stack);
|
||||
if (containingStack != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return this.maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
|
||||
{
|
||||
if (entity instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
ItemStack containingStack = getContainingItemStack(itemStack);
|
||||
|
||||
if (containingStack != null && !player.capabilities.isCreativeMode)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int) ((float) containingStack.stackSize / (float) TileCrate.getSlotCount(itemStack.getItemDamage())) * 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setContainingItemStack(ItemStack itemStack, ItemStack containingStack)
|
||||
{
|
||||
if (itemStack.stackTagCompound == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
NBTTagCompound itemTagCompound = new NBTTagCompound();
|
||||
containingStack.stackSize = Math.abs(containingStack.stackSize);
|
||||
containingStack.writeToNBT(itemTagCompound);
|
||||
itemStack.getTagCompound().setTag("Item", itemTagCompound);
|
||||
|
||||
itemStack.getTagCompound().setInteger("Count", containingStack.stackSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack.getTagCompound().setTag("Item", new NBTTagCompound());
|
||||
itemStack.getTagCompound().setInteger("Count", 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getContainingItemStack(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.stackTagCompound == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
return null;
|
||||
}
|
||||
|
||||
NBTTagCompound itemTagCompound = itemStack.getTagCompound().getCompoundTag("Item");
|
||||
ItemStack containingStack = ItemStack.loadItemStackFromNBT(itemTagCompound);
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
containingStack.stackSize = itemStack.getTagCompound().getInteger("Count");
|
||||
}
|
||||
|
||||
return containingStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int metadata)
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
{
|
||||
ItemStack containingItem = getContainingItemStack(stack);
|
||||
|
||||
if (world.getTileEntity(x, y, z) != null && containingItem != null)
|
||||
{
|
||||
if (containingItem.stackSize > 0)
|
||||
{
|
||||
TileCrate tileEntity = (TileCrate) world.getTileEntity(x, y, z);
|
||||
int count = containingItem.stackSize;
|
||||
|
||||
for (int slot = 0; slot < tileEntity.getInventory().getSizeInventory(); slot++)
|
||||
{
|
||||
int stackSize = Math.min(64, count);
|
||||
tileEntity.getInventory().setInventorySlotContents(slot, new ItemStack(containingItem.getItem(), stackSize, containingItem.getItemDamage()));
|
||||
count -= stackSize;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
containingItem = null;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
tileEntity.buildSampleStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
package resonantinduction.archaic.crate
|
||||
|
||||
import java.util.List
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.ItemBlock
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.potion.Potion
|
||||
import net.minecraft.potion.PotionEffect
|
||||
import net.minecraft.world.World
|
||||
import resonant.lib.utility.LanguageUtility
|
||||
import scala.util.control.Breaks._
|
||||
|
||||
object ItemBlockCrate {
|
||||
def setContainingItemStack(itemStack: ItemStack, containingStack: ItemStack) {
|
||||
if (itemStack.stackTagCompound == null) {
|
||||
itemStack.setTagCompound(new NBTTagCompound)
|
||||
}
|
||||
if (containingStack != null) {
|
||||
val itemTagCompound: NBTTagCompound = new NBTTagCompound
|
||||
containingStack.stackSize = Math.abs(containingStack.stackSize)
|
||||
containingStack.writeToNBT(itemTagCompound)
|
||||
itemStack.getTagCompound.setTag("Item", itemTagCompound)
|
||||
itemStack.getTagCompound.setInteger("Count", containingStack.stackSize)
|
||||
}
|
||||
else {
|
||||
itemStack.getTagCompound.setTag("Item", new NBTTagCompound)
|
||||
itemStack.getTagCompound.setInteger("Count", 0)
|
||||
}
|
||||
}
|
||||
|
||||
def getContainingItemStack(itemStack: ItemStack): ItemStack = {
|
||||
if (itemStack.stackTagCompound == null) {
|
||||
itemStack.setTagCompound(new NBTTagCompound)
|
||||
return null
|
||||
}
|
||||
val itemTagCompound: NBTTagCompound = itemStack.getTagCompound.getCompoundTag("Item")
|
||||
val containingStack: ItemStack = ItemStack.loadItemStackFromNBT(itemTagCompound)
|
||||
if (containingStack != null) {
|
||||
containingStack.stackSize = itemStack.getTagCompound.getInteger("Count")
|
||||
}
|
||||
return containingStack
|
||||
}
|
||||
}
|
||||
|
||||
class ItemBlockCrate(block: Block) extends ItemBlock(block: Block) {
|
||||
this.setHasSubtypes(true)
|
||||
|
||||
override def getUnlocalizedName(itemStack: ItemStack): String =
|
||||
{
|
||||
return this.getUnlocalizedName + "." + itemStack.getItemDamage
|
||||
}
|
||||
|
||||
override def addInformation(itemStack: ItemStack, par2EntityPlayer: EntityPlayer, list: List[_], par4: Boolean)
|
||||
{
|
||||
super.addInformation(itemStack, par2EntityPlayer, list, par4)
|
||||
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(itemStack)
|
||||
if (containingStack != null)
|
||||
{
|
||||
val s = LanguageUtility.getLocal("crate.tooltip.amount") + " " + containingStack.stackSize
|
||||
list.add(containingStack.getDisplayName.asInstanceOf[_])
|
||||
list.add(s.asInstanceOf[_])
|
||||
}
|
||||
}
|
||||
|
||||
override def getItemStackLimit(stack: ItemStack): Int =
|
||||
{
|
||||
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(stack)
|
||||
if (containingStack != null) {
|
||||
return 1
|
||||
}
|
||||
return this.maxStackSize
|
||||
}
|
||||
|
||||
override def onUpdate(itemStack: ItemStack, par2World: World, entity: Entity, par4: Int, par5: Boolean)
|
||||
{
|
||||
if (entity.isInstanceOf[EntityPlayer])
|
||||
{
|
||||
val player: EntityPlayer = entity.asInstanceOf[EntityPlayer]
|
||||
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(itemStack)
|
||||
if (containingStack != null && !player.capabilities.isCreativeMode)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (containingStack.stackSize.asInstanceOf[Float] / TileCrate.getSlotCount(itemStack.getItemDamage).asInstanceOf[Float]).asInstanceOf[Int] * 5))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def getMetadata(metadata: Int): Int =
|
||||
{
|
||||
return metadata
|
||||
}
|
||||
|
||||
override def placeBlockAt(stack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float, metadata: Int): Boolean =
|
||||
{
|
||||
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
{
|
||||
var containingItem: ItemStack = ItemBlockCrate.getContainingItemStack(stack)
|
||||
if (world.getTileEntity(x, y, z) != null && containingItem != null)
|
||||
{
|
||||
if (containingItem.stackSize > 0)
|
||||
{
|
||||
val tileEntity: TileCrate = world.getTileEntity(x, y, z).asInstanceOf[TileCrate]
|
||||
var count: Int = containingItem.stackSize
|
||||
for(slot <- tileEntity.getInventory.getSizeInventory)
|
||||
{
|
||||
val stackSize: Int = Math.min(64, count)
|
||||
tileEntity.getInventory.setInventorySlotContents(slot, new ItemStack(containingItem.getItem, stackSize, containingItem.getItemDamage))
|
||||
count -= stackSize
|
||||
if (count <= 0)
|
||||
{
|
||||
containingItem = null
|
||||
break
|
||||
}
|
||||
}
|
||||
tileEntity.buildSampleStack
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import universalelectricity.core.transform.vector.Vector3;
|
||||
import universalelectricity.api.vector.VectorHelper;
|
||||
import universalelectricity.core.transform.vector.VectorWorld;
|
||||
|
||||
/**
|
||||
* A class that allows flexible path finding in Minecraft Blocks. Back Ported from UE 1.3.0.
|
||||
|
@ -77,7 +77,9 @@ public class PathfinderCrate
|
|||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
TileEntity connectedTile = VectorHelper.getTileEntityFromSide(provider.worldObj, new Vector3(provider), ForgeDirection.getOrientation(i));
|
||||
VectorWorld vec = new VectorWorld(provider);
|
||||
vec.addEquals(ForgeDirection.getOrientation(i));
|
||||
TileEntity connectedTile = vec.getTileEntity();
|
||||
|
||||
if (!iteratedNodes.contains(connectedTile))
|
||||
{
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package resonantinduction.archaic.crate;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonant.lib.render.RenderItemOverlayUtility;
|
||||
import resonant.lib.utility.LanguageUtility;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderCrate extends TileEntitySpecialRenderer
|
||||
{
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
|
||||
{
|
||||
if (tileEntity instanceof TileCrate)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
TileCrate tile = (TileCrate) tileEntity;
|
||||
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getSampleStack(), x, y, z, LanguageUtility.getLocal("tooltip.empty"));
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package resonantinduction.archaic.crate
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import org.lwjgl.opengl.GL11
|
||||
import resonant.lib.render.RenderItemOverlayUtility
|
||||
import resonant.lib.utility.LanguageUtility
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
|
||||
@SideOnly(Side.CLIENT) class RenderCrate extends TileEntitySpecialRenderer {
|
||||
def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, var8: Float)
|
||||
{
|
||||
if (tileEntity.isInstanceOf[TileCrate])
|
||||
{
|
||||
GL11.glPushMatrix
|
||||
val tile: TileCrate = tileEntity.asInstanceOf[TileCrate]
|
||||
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getSampleStack, x, y, z, LanguageUtility.getLocal("tooltip.empty"))
|
||||
GL11.glPopMatrix
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue