mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
the press unshittening: part 2
This commit is contained in:
parent
cf62bc82e0
commit
6f2b9656fc
@ -20,8 +20,8 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MachineEPress extends BlockContainer {
|
||||
|
||||
private final Random field_149933_a = new Random();
|
||||
|
||||
private final Random field_149933_a = new Random();
|
||||
private static boolean keepInventory;
|
||||
|
||||
public MachineEPress(Material p_i45386_1_) {
|
||||
@ -47,96 +47,72 @@ public class MachineEPress extends BlockContainer {
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
|
||||
{
|
||||
if (!keepInventory)
|
||||
{
|
||||
ISidedInventory tileentityfurnace = (ISidedInventory)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
|
||||
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) {
|
||||
if(!keepInventory) {
|
||||
ISidedInventory tileentityfurnace = (ISidedInventory) p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
|
||||
|
||||
if (tileentityfurnace != null)
|
||||
{
|
||||
for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
|
||||
{
|
||||
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
|
||||
if(tileentityfurnace != null) {
|
||||
for(int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) {
|
||||
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
if(itemstack != null) {
|
||||
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
while (itemstack.stackSize > 0)
|
||||
{
|
||||
int j1 = this.field_149933_a.nextInt(21) + 10;
|
||||
while(itemstack.stackSize > 0) {
|
||||
int j1 = this.field_149933_a.nextInt(21) + 10;
|
||||
|
||||
if (j1 > itemstack.stackSize)
|
||||
{
|
||||
j1 = itemstack.stackSize;
|
||||
}
|
||||
if(j1 > itemstack.stackSize) {
|
||||
j1 = itemstack.stackSize;
|
||||
}
|
||||
|
||||
itemstack.stackSize -= j1;
|
||||
EntityItem entityitem = new EntityItem(p_149749_1_, p_149749_2_ + f, p_149749_3_ + f1, p_149749_4_ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
|
||||
itemstack.stackSize -= j1;
|
||||
EntityItem entityitem = new EntityItem(p_149749_1_, p_149749_2_ + f, p_149749_3_ + f1, p_149749_4_ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
|
||||
|
||||
if (itemstack.hasTagCompound())
|
||||
{
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
|
||||
}
|
||||
if(itemstack.hasTagCompound()) {
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
|
||||
}
|
||||
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float)this.field_149933_a.nextGaussian() * f3;
|
||||
entityitem.motionY = (float)this.field_149933_a.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float)this.field_149933_a.nextGaussian() * f3;
|
||||
p_149749_1_.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float) this.field_149933_a.nextGaussian() * f3;
|
||||
entityitem.motionY = (float) this.field_149933_a.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float) this.field_149933_a.nextGaussian() * f3;
|
||||
p_149749_1_.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
|
||||
}
|
||||
}
|
||||
p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
|
||||
}
|
||||
}
|
||||
|
||||
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
|
||||
}
|
||||
|
||||
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
|
||||
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
|
||||
if(i == 0)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
|
||||
}
|
||||
if(i == 1)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
|
||||
}
|
||||
if(i == 2)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
|
||||
}
|
||||
if(i == 3)
|
||||
{
|
||||
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
|
||||
}
|
||||
|
||||
if(itemStack.hasDisplayName())
|
||||
{
|
||||
((TileEntityMachineEPress)world.getTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
|
||||
|
||||
if(i == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2);
|
||||
if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2);
|
||||
if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2);
|
||||
if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2);
|
||||
|
||||
if(itemStack.hasDisplayName()) {
|
||||
((TileEntityMachineEPress) world.getTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
if(world.isRemote)
|
||||
{
|
||||
if(world.isRemote) {
|
||||
return true;
|
||||
} else if(!player.isSneaking())
|
||||
{
|
||||
} else if(!player.isSneaking()) {
|
||||
TileEntityMachineEPress entity = (TileEntityMachineEPress) world.getTileEntity(x, y, z);
|
||||
if(entity != null)
|
||||
{
|
||||
if(entity != null) {
|
||||
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.inventory.SlotMachineOutput;
|
||||
import com.hbm.inventory.SlotUpgrade;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.machine.IItemFluidIdentifier;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade;
|
||||
import com.hbm.items.machine.ItemStamp;
|
||||
import com.hbm.tileentity.machine.TileEntityMachineEPress;
|
||||
|
||||
import api.hbm.energy.IBatteryItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@ -13,8 +19,6 @@ public class ContainerMachineEPress extends Container {
|
||||
|
||||
private TileEntityMachineEPress nukeBoy;
|
||||
|
||||
private int progress;
|
||||
|
||||
public ContainerMachineEPress(InventoryPlayer invPlayer, TileEntityMachineEPress tedf) {
|
||||
|
||||
nukeBoy = tedf;
|
||||
@ -27,83 +31,66 @@ private TileEntityMachineEPress nukeBoy;
|
||||
this.addSlotToContainer(new Slot(tedf, 2, 80, 53));
|
||||
//Output
|
||||
this.addSlotToContainer(new SlotMachineOutput(tedf, 3, 140, 35));
|
||||
//Upgrade
|
||||
this.addSlotToContainer(new SlotUpgrade(tedf, 4, 44, 21));
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int j = 0; j < 9; j++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 9; j++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2)
|
||||
{
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) {
|
||||
ItemStack var3 = null;
|
||||
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
||||
|
||||
if (var4 != null && var4.getHasStack())
|
||||
{
|
||||
|
||||
if(var4 != null && var4.getHasStack()) {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
|
||||
if (par2 <= 3) {
|
||||
if (!this.mergeItemStack(var5, 4, this.inventorySlots.size(), true))
|
||||
{
|
||||
|
||||
if(par2 <= 4) {
|
||||
if(!this.mergeItemStack(var5, 5, this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(var5, 2, 3, false))
|
||||
if (!this.mergeItemStack(var5, 0, 1, false))
|
||||
if (!this.mergeItemStack(var5, 1, 2, false))
|
||||
} else {
|
||||
|
||||
if(var3.getItem() instanceof IBatteryItem || var3.getItem() == ModItems.battery_creative) {
|
||||
if(!this.mergeItemStack(var5, 0, 1, false)) {
|
||||
return null;
|
||||
|
||||
if (var5.stackSize == 0)
|
||||
{
|
||||
var4.putStack((ItemStack) null);
|
||||
}
|
||||
} else if(var3.getItem() instanceof ItemMachineUpgrade) {
|
||||
if(!this.mergeItemStack(var5, 4, 5, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if(var3.getItem() instanceof ItemStamp) {
|
||||
if(!this.mergeItemStack(var5, 1, 2, false)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if(!this.mergeItemStack(var5, 2, 3, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
} else {
|
||||
var4.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return var3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return nukeBoy.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for(int i = 0; i < this.crafters.size(); i++)
|
||||
{
|
||||
ICrafting par1 = (ICrafting)this.crafters.get(i);
|
||||
|
||||
if(this.progress != this.nukeBoy.progress)
|
||||
{
|
||||
par1.sendProgressBarUpdate(this, 0, this.nukeBoy.progress);
|
||||
}
|
||||
}
|
||||
|
||||
this.progress = this.nukeBoy.progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
if(i == 0)
|
||||
{
|
||||
nukeBoy.progress = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.inventory.SlotMachineOutput;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade;
|
||||
import com.hbm.items.machine.ItemStamp;
|
||||
import com.hbm.tileentity.machine.TileEntityMachinePress;
|
||||
|
||||
import api.hbm.energy.IBatteryItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
|
||||
public class ContainerMachinePress extends Container {
|
||||
|
||||
@ -49,10 +54,22 @@ public class ContainerMachinePress extends Container {
|
||||
if(!this.mergeItemStack(var5, 4, this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if(!this.mergeItemStack(var5, 2, 3, false))
|
||||
if(!this.mergeItemStack(var5, 0, 1, false))
|
||||
if(!this.mergeItemStack(var5, 1, 2, false))
|
||||
} else {
|
||||
|
||||
if(TileEntityFurnace.isItemFuel(var3)) {
|
||||
if(!this.mergeItemStack(var5, 0, 1, false)) {
|
||||
return null;
|
||||
}
|
||||
} else if(var3.getItem() instanceof ItemStamp) {
|
||||
if(!this.mergeItemStack(var5, 1, 2, false)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if(!this.mergeItemStack(var5, 2, 3, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
|
||||
@ -27,7 +27,7 @@ public class GUIMachineEPress extends GuiInfoContainer {
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
|
||||
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 26, guiTop + 69 - 52, 16, 52, press.power, press.maxPower);
|
||||
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 17, guiTop + 69 - 52, 16, 52, press.power, press.maxPower);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,10 +44,10 @@ public class GUIMachineEPress extends GuiInfoContainer {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
int i = (int)press.getPowerScaled(52);
|
||||
drawTexturedModalRect(guiLeft + 26, guiTop + 69 - i, 176, 52 - i, 16, i);
|
||||
int i = (int) (press.power * 52 / press.maxPower);
|
||||
drawTexturedModalRect(guiLeft + 17, guiTop + 69 - i, 176, 52 - i, 16, i);
|
||||
|
||||
int k = press.getProgressScaled(16);
|
||||
this.drawTexturedModalRect(guiLeft + 79, guiTop + 35, 192, 0, 18, k);
|
||||
int k = (int) (press.renderPress * 16 / press.maxPress);
|
||||
this.drawTexturedModalRect(guiLeft + 79, guiTop + 35, 192, 0, 18, k);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,9 +10,9 @@ import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
|
||||
@ -29,14 +29,10 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
GL11.glRotatef(180, 0F, 1F, 0F);
|
||||
|
||||
switch(tileentity.getBlockMetadata()) {
|
||||
case 2:
|
||||
GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4:
|
||||
GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3:
|
||||
GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
case 5:
|
||||
GL11.glRotatef(180, 0F, 1F, 0F); break;
|
||||
case 2: GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4: GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3: GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
case 5: GL11.glRotatef(180, 0F, 1F, 0F); break;
|
||||
}
|
||||
|
||||
this.bindTexture(ResourceManager.epress_body_tex);
|
||||
@ -45,29 +41,25 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
renderTileEntityAt2(tileentity, x, y, z, f);
|
||||
renderTileEntityAt2(tileentity, x, y, z, f);
|
||||
}
|
||||
|
||||
|
||||
public void renderTileEntityAt2(TileEntity tileentity, double x, double y, double z, float f) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5D, y + 1 + 1 - 0.125, z + 0.5D);
|
||||
GL11.glTranslated(x + 0.5D, y + 1, z + 0.5D);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glRotatef(180, 0F, 1F, 0F);
|
||||
|
||||
switch(tileentity.getBlockMetadata()) {
|
||||
case 2:
|
||||
GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4:
|
||||
GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3:
|
||||
GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
case 5:
|
||||
GL11.glRotatef(180, 0F, 1F, 0F); break;
|
||||
case 2: GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4: GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3: GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
case 5: GL11.glRotatef(180, 0F, 1F, 0F); break;
|
||||
}
|
||||
|
||||
TileEntityMachineEPress press = (TileEntityMachineEPress)tileentity;
|
||||
float f1 = press.progress * (1 - 0.125F) / press.maxProgress;
|
||||
GL11.glTranslated(0, -f1, 0);
|
||||
double p = (press.lastPress + (press.renderPress - press.lastPress) * f) /(double) press.maxPress;
|
||||
GL11.glTranslated(0, MathHelper.clamp_double((1D - p), 0D, 1D) * 0.875D, 0);
|
||||
|
||||
this.bindTexture(ResourceManager.epress_head_tex);
|
||||
|
||||
@ -75,9 +67,9 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
renderTileEntityAt3(tileentity, x, y, z, f);
|
||||
}
|
||||
|
||||
renderTileEntityAt3(tileentity, x, y, z, f);
|
||||
}
|
||||
|
||||
public void renderTileEntityAt3(TileEntity tileentity, double x, double y, double z, float f) {
|
||||
itemRenderer = new RenderDecoItem(this);
|
||||
itemRenderer.setRenderManager(renderManager);
|
||||
@ -103,16 +95,18 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
GL11.glTranslatef(-1, -1.15F, 0);
|
||||
|
||||
TileEntityMachineEPress press = (TileEntityMachineEPress)tileentity;
|
||||
ItemStack stack = new ItemStack(Item.getItemById(press.item), 1, press.meta);
|
||||
|
||||
EntityItem item = new EntityItem(null, 0.0D, 0.0D, 0.0D, stack);
|
||||
item.getEntityItem().stackSize = 1;
|
||||
item.hoverStart = 0.0F;
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
this.itemRenderer.doRender(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
RenderItem.renderInFrame = false;
|
||||
if(press.syncStack != null) {
|
||||
ItemStack stack = press.syncStack.copy();
|
||||
|
||||
EntityItem item = new EntityItem(null, 0.0D, 0.0D, 0.0D, stack);
|
||||
item.getEntityItem().stackSize = 1;
|
||||
item.hoverStart = 0.0F;
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
this.itemRenderer.doRender(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
RenderItem.renderInFrame = false;
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,8 +54,8 @@ public class RenderPress extends TileEntitySpecialRenderer {
|
||||
GL11.glPopMatrix();
|
||||
|
||||
renderTileEntityAt3(tileEntity, x, y, z, f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void renderTileEntityAt3(TileEntity tileEntity, double x, double y, double z, float f) {
|
||||
itemRenderer = new RenderDecoItem(this);
|
||||
itemRenderer.setRenderManager(renderManager);
|
||||
|
||||
@ -1,113 +1,172 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import com.hbm.inventory.UpgradeManager;
|
||||
import com.hbm.inventory.container.ContainerMachineEPress;
|
||||
import com.hbm.inventory.gui.GUIMachineEPress;
|
||||
import com.hbm.inventory.recipes.PressRecipes;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
||||
import com.hbm.items.machine.ItemStamp;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.packet.AuxElectricityPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineEPress extends TileEntityLoadedBase implements ISidedInventory, IEnergyUser, IGUIProvider {
|
||||
public class TileEntityMachineEPress extends TileEntityMachineBase implements IEnergyUser, IGUIProvider {
|
||||
|
||||
private ItemStack slots[];
|
||||
|
||||
public int progress = 0;
|
||||
public long power = 0;
|
||||
public final static int maxProgress = 200;
|
||||
public final static long maxPower = 50000;
|
||||
public int item;
|
||||
public int meta;
|
||||
|
||||
public int press;
|
||||
public double renderPress;
|
||||
public double lastPress;
|
||||
private int syncPress;
|
||||
private int turnProgress;
|
||||
public final static int maxPress = 200;
|
||||
boolean isRetracting = false;
|
||||
private int delay;
|
||||
|
||||
private String customName;
|
||||
public ItemStack syncStack;
|
||||
|
||||
public TileEntityMachineEPress() {
|
||||
slots = new ItemStack[4];
|
||||
super(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return slots.length;
|
||||
public String getName() {
|
||||
return "container.epress";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return slots[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
if(slots[i] != null)
|
||||
{
|
||||
ItemStack itemStack = slots[i];
|
||||
slots[i] = null;
|
||||
return itemStack;
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.updateConnections();
|
||||
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
boolean canProcess = this.canProcess();
|
||||
|
||||
if((canProcess || this.isRetracting || this.delay > 0) && power >= 100) {
|
||||
|
||||
power -= 100;
|
||||
|
||||
if(delay <= 0) {
|
||||
|
||||
UpgradeManager.eval(slots, 4, 4);
|
||||
int speed = 1 + Math.min(3, UpgradeManager.getLevel(UpgradeType.SPEED));
|
||||
|
||||
int stampSpeed = this.isRetracting ? 20 : 45;
|
||||
stampSpeed *= (1D + (double) speed / 4D);
|
||||
|
||||
if(this.isRetracting) {
|
||||
this.press -= stampSpeed;
|
||||
|
||||
if(this.press <= 0) {
|
||||
this.isRetracting = false;
|
||||
this.delay = 5 - speed + 1;
|
||||
}
|
||||
} else if(canProcess) {
|
||||
this.press += stampSpeed;
|
||||
|
||||
if(this.press >= this.maxPress) {
|
||||
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", 1.5F, 1.0F);
|
||||
ItemStack output = PressRecipes.getOutput(slots[2], slots[1]);
|
||||
if(slots[3] == null) {
|
||||
slots[3] = output.copy();
|
||||
} else {
|
||||
slots[3].stackSize += output.stackSize;
|
||||
}
|
||||
this.decrStackSize(2, 1);
|
||||
|
||||
if(slots[1].getMaxDamage() != 0) {
|
||||
slots[1].setItemDamage(slots[1].getItemDamage() + 1);
|
||||
if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) {
|
||||
slots[1] = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.isRetracting = true;
|
||||
this.delay = 5 - speed + 1;
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
} else if(this.press > 0){
|
||||
this.isRetracting = true;
|
||||
}
|
||||
} else {
|
||||
delay--;
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("power", power);
|
||||
data.setInteger("press", press);
|
||||
if(slots[2] != null) {
|
||||
NBTTagCompound stack = new NBTTagCompound();
|
||||
slots[2].writeToNBT(stack);
|
||||
data.setTag("stack", stack);
|
||||
}
|
||||
|
||||
this.networkPack(data, 50);
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
||||
slots[i] = itemStack;
|
||||
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit())
|
||||
{
|
||||
itemStack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return this.hasCustomInventoryName() ? this.customName : "container.epress";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return this.customName != null && this.customName.length() > 0;
|
||||
}
|
||||
|
||||
public void setCustomName(String name) {
|
||||
this.customName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
|
||||
{
|
||||
return false;
|
||||
}else{
|
||||
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64;
|
||||
|
||||
// approach-based interpolation, GO!
|
||||
this.lastPress = this.renderPress;
|
||||
|
||||
if(this.turnProgress > 0) {
|
||||
this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress);
|
||||
--this.turnProgress;
|
||||
} else {
|
||||
this.renderPress = this.syncPress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {}
|
||||
@Override
|
||||
public void closeInventory() {}
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.power = nbt.getLong("power");
|
||||
this.syncPress = nbt.getInteger("press");
|
||||
|
||||
if(nbt.hasKey("stack")) {
|
||||
NBTTagCompound stack = nbt.getCompoundTag("stack");
|
||||
this.syncStack = ItemStack.loadItemStackFromNBT(stack);
|
||||
} else {
|
||||
this.syncStack = null;
|
||||
}
|
||||
|
||||
this.turnProgress = 2;
|
||||
}
|
||||
|
||||
public boolean canProcess() {
|
||||
if(power < 100) return false;
|
||||
if(slots[1] == null || slots[2] == null) return false;
|
||||
|
||||
ItemStack output = PressRecipes.getOutput(slots[2], slots[1]);
|
||||
|
||||
if(output == null) return false;
|
||||
|
||||
if(slots[3] == null) return true;
|
||||
if(slots[3].stackSize + output.stackSize <= slots[3].getMaxStackSize() && slots[3].getItem() == output.getItem() && slots[3].getItemDamage() == output.getItemDamage()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
||||
@ -119,76 +178,9 @@ public class TileEntityMachineEPress extends TileEntityLoadedBase implements ISi
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if(slots[i] != null)
|
||||
{
|
||||
if(slots[i].stackSize <= j)
|
||||
{
|
||||
ItemStack itemStack = slots[i];
|
||||
slots[i] = null;
|
||||
return itemStack;
|
||||
}
|
||||
ItemStack itemStack1 = slots[i].splitStack(j);
|
||||
if (slots[i].stackSize == 0)
|
||||
{
|
||||
slots[i] = null;
|
||||
}
|
||||
|
||||
return itemStack1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] { 1, 2, 3 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
NBTTagList list = nbt.getTagList("items", 10);
|
||||
|
||||
progress = nbt.getInteger("progress");
|
||||
power = nbt.getInteger("power");
|
||||
isRetracting = nbt.getBoolean("ret");
|
||||
|
||||
slots = new ItemStack[getSizeInventory()];
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
|
||||
byte b0 = nbt1.getByte("slot");
|
||||
if(b0 >= 0 && b0 < slots.length)
|
||||
{
|
||||
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
nbt.setInteger("progress", progress);
|
||||
nbt.setLong("power", power);
|
||||
nbt.setBoolean("ret", isRetracting);
|
||||
|
||||
for(int i = 0; i < slots.length; i++)
|
||||
{
|
||||
if(slots[i] != null)
|
||||
{
|
||||
NBTTagCompound nbt1 = new NBTTagCompound();
|
||||
nbt1.setByte("slot", (byte)i);
|
||||
slots[i].writeToNBT(nbt1);
|
||||
list.appendTag(nbt1);
|
||||
}
|
||||
}
|
||||
nbt.setTag("items", list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return new int[]{ 1, 2, 3 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemStack, int j) {
|
||||
@ -201,99 +193,21 @@ public class TileEntityMachineEPress extends TileEntityLoadedBase implements ISi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
|
||||
if(power >= 100) {
|
||||
|
||||
int speed = 25;
|
||||
|
||||
if(slots[1] != null && slots[2] != null) {
|
||||
ItemStack stack = PressRecipes.getOutput(slots[2], slots[1]);
|
||||
if(stack != null &&
|
||||
(slots[3] == null ||
|
||||
(slots[3].getItem() == stack.getItem() &&
|
||||
slots[3].stackSize + stack.stackSize <= slots[3].getMaxStackSize()))) {
|
||||
|
||||
power -= 100;
|
||||
|
||||
if(progress >= maxProgress) {
|
||||
|
||||
isRetracting = true;
|
||||
|
||||
if(slots[3] == null)
|
||||
slots[3] = stack.copy();
|
||||
else
|
||||
slots[3].stackSize += stack.stackSize;
|
||||
|
||||
slots[2].stackSize--;
|
||||
if(slots[2].stackSize <= 0)
|
||||
slots[2] = null;
|
||||
|
||||
if(slots[1].getMaxDamage() != 0) {
|
||||
slots[1].setItemDamage(slots[1].getItemDamage() + 1);
|
||||
if(slots[1].getItemDamage() >= slots[1].getMaxDamage())
|
||||
slots[1] = null;
|
||||
}
|
||||
|
||||
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", 1.5F, 1.0F);
|
||||
}
|
||||
|
||||
if(!isRetracting)
|
||||
progress += speed;
|
||||
|
||||
} else {
|
||||
isRetracting = true;
|
||||
}
|
||||
} else {
|
||||
isRetracting = true;
|
||||
}
|
||||
|
||||
if(isRetracting)
|
||||
progress -= speed;
|
||||
} else {
|
||||
isRetracting = true;
|
||||
}
|
||||
|
||||
if(progress <= 0) {
|
||||
isRetracting = false;
|
||||
progress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConnections() {
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
|
||||
}
|
||||
|
||||
public long getPowerScaled(int i) {
|
||||
return (power * i) / maxPower;
|
||||
}
|
||||
|
||||
public int getProgressScaled(int i) {
|
||||
return (progress * i) / maxProgress;
|
||||
press = nbt.getInteger("press");
|
||||
power = nbt.getInteger("power");
|
||||
isRetracting = nbt.getBoolean("ret");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared()
|
||||
{
|
||||
return 65536.0D;
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger("press", press);
|
||||
nbt.setLong("power", power);
|
||||
nbt.setBoolean("ret", isRetracting);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -311,6 +225,24 @@ public class TileEntityMachineEPress extends TileEntityLoadedBase implements ISi
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
AxisAlignedBB aabb;
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
if(aabb != null)
|
||||
return aabb;
|
||||
|
||||
aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1);
|
||||
return aabb;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
return 65536.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.8 KiB |
Loading…
x
Reference in New Issue
Block a user