Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/net/quetzi/bluepower/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@

package net.quetzi.bluepower;

import com.mojang.authlib.GameProfile;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.quetzi.bluepower.references.Refs;

public class CommonProxy {

public static EntityPlayer fakePlayer;

public void init() {

}
Expand All @@ -29,6 +37,14 @@ public void initRenderers() {

}

public EntityPlayer getFakePlayer(World world) {
if(fakePlayer == null) {
fakePlayer = FakePlayerFactory.get((WorldServer) world, new GameProfile(Refs.MODID, "Bluepower"));
}

return fakePlayer;
}

public EntityPlayer getPlayer() {

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.quetzi.bluepower.blocks.machines;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.quetzi.bluepower.blocks.BlockContainerBase;
import net.quetzi.bluepower.init.CustomTabs;
import net.quetzi.bluepower.references.GuiIDs;
import net.quetzi.bluepower.references.Refs;
import net.quetzi.bluepower.tileentities.tier2.TileEntityAssembler;

public class BlockAssembler extends BlockContainerBase {

public IIcon front;
public IIcon back;
public IIcon active;

public BlockAssembler() {
super(Material.iron);
this.setBlockName(Refs.ASSEMBLER_NAME);
this.setCreativeTab(CustomTabs.tabBluePowerMachines);
}

@Override
protected Class<? extends TileEntity> getTileEntity() {
return TileEntityAssembler.class;
}

@Override
public GuiIDs getGuiID() {
return GuiIDs.ASSEMBLER_ID;
}

@Override
public IIcon getIcon(int side, int meta) {
ForgeDirection orientation = ForgeDirection.getOrientation(meta);

if(side == orientation.ordinal()) {
return this.front;
} else if(side == orientation.getOpposite().ordinal()) {
return this.back;
}

return this.blockIcon;
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {

//TODO : Add the animated textures

String name = getUnlocalizedName().substring(5);

this.blockIcon = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + name + "_side_0");
this.active = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + name + "_front_active");
this.front = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + name + "_front");
this.back = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + name + "_bottom");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.quetzi.bluepower.items.ItemSeedBag;
import net.quetzi.bluepower.references.GuiIDs;
import net.quetzi.bluepower.tileentities.tier1.*;
import net.quetzi.bluepower.tileentities.tier2.TileAssembler;
import net.quetzi.bluepower.tileentities.tier2.TileSortingMachine;
import net.quetzi.bluepower.tileentities.tier3.*;

Expand Down Expand Up @@ -87,6 +88,8 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int
return new ContainerRelay(player.inventory, (TileRelay) ent);
case EJECTOR_ID:
return new ContainerEjector(player.inventory, (TileEjector) ent);
case ASSEMBLER_ID:
return new ContainerAssembler(player.inventory, (TileAssembler) ent);
default:
break;
}
Expand Down Expand Up @@ -142,9 +145,11 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
return new GuiRelay(player.inventory, (TileRelay) ent);
case EJECTOR_ID:
return new GuiEjector(player.inventory, (TileEjector) ent);
case ASSEMBLER_ID:
return new GuiAssembler(player.inventory, (TileAssembler) ent);
default:
break;
}
return null;
}
}
}
49 changes: 49 additions & 0 deletions src/main/java/net/quetzi/bluepower/client/gui/GuiAssembler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.quetzi.bluepower.client.gui;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.quetzi.bluepower.containers.ContainerAssembler;
import net.quetzi.bluepower.references.Refs;
import net.quetzi.bluepower.tileentities.tier2.TileEntityAssembler;

public class GuiAssembler extends GuiBase {

private static final ResourceLocation resLoc = new ResourceLocation(Refs.MODID, "textures/gui/assembler.png");

public TileEntityAssembler assembler;

public GuiAssembler(InventoryPlayer invP, TileEntityAssembler tile) {
super(new ContainerAssembler(invP, tile), resLoc);
this.ySize = 195;
this.assembler = tile;
}

@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
super.drawGuiContainerBackgroundLayer(f, i, j);

int x = (width - xSize) / 2;
int y = (height - ySize) / 2;

this.drawTexturedModalRect(x + 6 + this.addXAmount(), y + 16 + this.addYAmount(), 176, 0, 20, 20);
}

private int addYAmount() {
if(this.assembler.currentSlot <= 7) {
return 0;
} else {
return 18;
}
}

private int addXAmount() {
if(this.assembler.currentSlot <= 7) {
return 18 * this.assembler.currentSlot;
} else {
int i = this.assembler.currentSlot - 8;
return 18 * i;
}
}

}
193 changes: 193 additions & 0 deletions src/main/java/net/quetzi/bluepower/containers/ContainerAssembler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package net.quetzi.bluepower.containers;

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;
import net.quetzi.bluepower.containers.slots.IPhantomSlot;
import net.quetzi.bluepower.containers.slots.SlotPhantom;
import net.quetzi.bluepower.tileentities.tier2.TileEntityAssembler;

public class ContainerAssembler extends Container {

private TileEntityAssembler assembler;

public int lastSlot = 0;

public ContainerAssembler(InventoryPlayer invP, TileEntityAssembler ass) {
this.assembler = ass;

int slotID = 0;

for(int i = 0;i < 2;i++) {
for(int j = 0;j < 8;j++) {
this.addSlotToContainer(new SlotPhantom(this.assembler, slotID, 8 + j * 18, 18 + i * 18));
slotID++;
}
}

for(int i = 0;i < 2;i++) {
for(int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(this.assembler, slotID, 8 + j * 18, 63 + i * 18));
slotID++;
}
}

for (int i = 0;i < 3;i++) {
for (int j = 0;j < 9;j++) {
this.addSlotToContainer(new Slot(invP, j + i * 9 + 9, 8 + j * 18, 113 + i * 18));
}
}
for (int i = 0;i < 9;i++)
this.addSlotToContainer(new Slot(invP, i, 8 + i * 18, 171));
}

@Override
public boolean canInteractWith(EntityPlayer var1) {
return true;
}

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
//TODO : ^
return super.transferStackInSlot(par1EntityPlayer, par2);
}

@Override
public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) {

Slot slot = slotNum < 0 ? null : (Slot) inventorySlots.get(slotNum);
if (slot instanceof IPhantomSlot) {
return slotClickPhantom(slot, mouseButton, modifier, player);
}
return super.slotClick(slotNum, mouseButton, modifier, player);
}

/**
* This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
* @author CovertJaguar <http://www.railcraft.info>
*/
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) {

ItemStack stack = null;

if (mouseButton == 2) {
if (((IPhantomSlot) slot).canAdjust()) {
slot.putStack(null);
}
} else if (mouseButton == 0 || mouseButton == 1) {
InventoryPlayer playerInv = player.inventory;
slot.onSlotChanged();
ItemStack stackSlot = slot.getStack();
ItemStack stackHeld = playerInv.getItemStack();

if (stackSlot != null) {
stack = stackSlot.copy();
}

if (stackSlot == null) {
if (stackHeld != null && slot.isItemValid(stackHeld)) {
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
}
} else if (stackHeld == null) {
adjustPhantomSlot(slot, mouseButton, modifier);
slot.onPickupFromSlot(player, playerInv.getItemStack());
} else if (slot.isItemValid(stackHeld)) {
if (canStacksMerge(stackSlot, stackHeld)) {
adjustPhantomSlot(slot, mouseButton, modifier);
} else {
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
}
}
}

return stack;
}

/**
* This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
* @author CovertJaguar <http://www.railcraft.info>
*/
public boolean canStacksMerge(ItemStack stack1, ItemStack stack2) {

if (stack1 == null || stack2 == null) return false;
if (!stack1.isItemEqual(stack2)) return false;
if (!ItemStack.areItemStackTagsEqual(stack1, stack2)) return false;
return true;

}

/**
* This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
* @author CovertJaguar <http://www.railcraft.info>
*/
protected void adjustPhantomSlot(Slot slot, int mouseButton, int modifier) {

if (!((IPhantomSlot) slot).canAdjust()) {
return;
}
ItemStack stackSlot = slot.getStack();
int stackSize;
if (modifier == 1) {
stackSize = mouseButton == 0 ? (stackSlot.stackSize + 1) / 2 : stackSlot.stackSize * 2;
} else {
stackSize = mouseButton == 0 ? stackSlot.stackSize - 1 : stackSlot.stackSize + 1;
}

if (stackSize > slot.getSlotStackLimit()) {
stackSize = slot.getSlotStackLimit();
}

stackSlot.stackSize = stackSize;

if (stackSlot.stackSize <= 0) {
slot.putStack((ItemStack) null);
}
}

protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier) {

if (!((IPhantomSlot) slot).canAdjust()) {
return;
}
int stackSize = mouseButton == 0 ? stackHeld.stackSize : 1;
if (stackSize > slot.getSlotStackLimit()) {
stackSize = slot.getSlotStackLimit();
}
ItemStack phantomStack = stackHeld.copy();
phantomStack.stackSize = stackSize;

slot.putStack(phantomStack);
}

@Override
public void addCraftingToCrafters(ICrafting par1ICrafting) {
super.addCraftingToCrafters(par1ICrafting);
par1ICrafting.sendProgressBarUpdate(this, 0, this.assembler.currentSlot);
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();

for(int i = 0; i < this.crafters.size(); ++i) {
ICrafting icrafting = (ICrafting) this.crafters.get(i);

if(this.lastSlot != this.assembler.currentSlot) {
icrafting.sendProgressBarUpdate(this, 0, this.assembler.currentSlot);
}
}

this.lastSlot = this.assembler.currentSlot;
}

@Override
public void updateProgressBar(int par1, int par2) {
if(par1 == 0) {
this.assembler.currentSlot = par2;
}
}

}
Loading