Fluid API update

Brace formatting
This commit is contained in:
Chicken-Bones committed 2015-04-17 16:46:06 +10:00
1 parent 5731f08f10
commit 6c569d562d
6 files changed
+103 -131

No files matched your search

+3 -3
View File
@@ -1,4 +1,4 @@
mc_version=1.7.10
forge_version=10.13.0.1151
ccl_version=1.1.1.99
mod_version=1.0.4
forge_version=10.13.3.1373-1.7.10
ccl_version=1.1.3.134
mod_version=1.0.5
+1
View File
@@ -63,6 +63,7 @@ public class ServerUtils extends CommonUtils
throw new RuntimeException(e);
}
}
public static GameProfile getGameProfile(String username) {
EntityPlayer player = getPlayer(username);
if(player != null)
@@ -38,8 +38,9 @@ public class CodeChickenCoreModContainer extends DummyModContainer
public List<ArtifactVersion> getDependants() {
LinkedList<ArtifactVersion> deps = new LinkedList<ArtifactVersion>();
if(!getVersion().contains("$")) {
deps.add(VersionParser.parseVersionReference("Forge@[10.13.3,)"));
deps.add(VersionParser.parseVersionReference("NotEnoughItems@[1.0.3,)"));
deps.add(VersionParser.parseVersionReference("EnderStorage@[1.4.5,)"));
deps.add(VersionParser.parseVersionReference("EnderStorage@[1.4.7,)"));
deps.add(VersionParser.parseVersionReference("ChickenChunks@[1.3.4,)"));
deps.add(VersionParser.parseVersionReference("Translocator@[1.1.1,)"));
deps.add(VersionParser.parseVersionReference("WR-CBE|Core@[1.4.1,)"));
@@ -13,13 +13,12 @@ public class ExtendedFluidTank implements IFluidTank
public ExtendedFluidTank(FluidStack type, int capacity)
{
if(type == null)
{
fluid = new FluidStack(0, 0);
if(type == null) {
type = FluidUtils.water;
changeType = true;
}
else
fluid = FluidUtils.copy(type, 0);
fluid = FluidUtils.copy(type, 0);
this.capacity = capacity;
}
@@ -42,13 +41,13 @@ public class ExtendedFluidTank implements IFluidTank
public boolean canAccept(FluidStack type)
{
return type == null || type.fluidID <= 0 || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type);
return type == null || (fluid.amount == 0 && changeType) || fluid.isFluidEqual(type);
}
@Override
public int fill(FluidStack resource, boolean doFill)
{
if(resource == null || resource.fluidID <= 0)
if(resource == null)
return 0;
if(!canAccept(resource))
+5 -2
View File
@@ -1,6 +1,5 @@
package codechicken.core.fluid;
import codechicken.core.CommonUtils;
import codechicken.lib.inventory.InventoryUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -77,7 +76,7 @@ public class FluidUtils
public static FluidStack read(NBTTagCompound tag)
{
FluidStack stack = FluidStack.loadFluidStackFromNBT(tag);
return stack != null ? stack : new FluidStack(0, 0);
return stack != null ? stack : FluidUtils.emptyFluid();
}
public static NBTTagCompound write(FluidStack fluid, NBTTagCompound tag)
@@ -95,4 +94,8 @@ public class FluidUtils
light=(int)(light*density);
return light;
}
public static FluidStack emptyFluid() {
return new FluidStack(water, 0);
}
}
@@ -16,111 +16,93 @@ import net.minecraft.inventory.Slot;
public abstract class ContainerExtended extends Container implements ICrafting
{
public LinkedList<EntityPlayerMP> playerCrafters = new LinkedList<EntityPlayerMP>();
public ContainerExtended()
{
public ContainerExtended() {
crafters.add(this);
}
@Override
public void addCraftingToCrafters(ICrafting icrafting)
{
if(icrafting instanceof EntityPlayerMP)
{
public void addCraftingToCrafters(ICrafting icrafting) {
if (icrafting instanceof EntityPlayerMP) {
playerCrafters.add((EntityPlayerMP) icrafting);
sendContainerAndContentsToPlayer(this, getInventory(), Arrays.asList((EntityPlayerMP) icrafting));
detectAndSendChanges();
}
else
} else
super.addCraftingToCrafters(icrafting);
}
@Override
public void removeCraftingFromCrafters(ICrafting icrafting)
{
if(icrafting instanceof EntityPlayerMP)
public void removeCraftingFromCrafters(ICrafting icrafting) {
if (icrafting instanceof EntityPlayerMP)
playerCrafters.remove(icrafting);
else
super.removeCraftingFromCrafters(icrafting);
}
@Override
public void sendContainerAndContentsToPlayer(Container container, List list)
{
public void sendContainerAndContentsToPlayer(Container container, List list) {
sendContainerAndContentsToPlayer(container, list, playerCrafters);
}
public void sendContainerAndContentsToPlayer(Container container, List<ItemStack> list, List<EntityPlayerMP> playerCrafters)
{
public void sendContainerAndContentsToPlayer(Container container, List<ItemStack> list, List<EntityPlayerMP> playerCrafters) {
LinkedList<ItemStack> largeStacks = new LinkedList<ItemStack>();
for(int i = 0; i < list.size(); i++)
{
for (int i = 0; i < list.size(); i++) {
ItemStack stack = list.get(i);
if(stack != null && stack.stackSize > Byte.MAX_VALUE)
{
if (stack != null && stack.stackSize > Byte.MAX_VALUE) {
list.set(i, null);
largeStacks.add(stack);
}
else
} else
largeStacks.add(null);
}
for(EntityPlayerMP player : playerCrafters)
for (EntityPlayerMP player : playerCrafters)
player.sendContainerAndContentsToPlayer(container, list);
for(int i = 0; i < largeStacks.size(); i++)
{
for (int i = 0; i < largeStacks.size(); i++) {
ItemStack stack = largeStacks.get(i);
if(stack != null)
if (stack != null)
sendLargeStack(stack, i, playerCrafters);
}
}
public void sendLargeStack(ItemStack stack, int slot, List<EntityPlayerMP> players)
{
public void sendLargeStack(ItemStack stack, int slot, List<EntityPlayerMP> players) {
}
@Override
public void sendProgressBarUpdate(Container container, int i, int j)
{
for(EntityPlayerMP player : playerCrafters)
public void sendProgressBarUpdate(Container container, int i, int j) {
for (EntityPlayerMP player : playerCrafters)
player.sendProgressBarUpdate(container, i, j);
}
@Override
public void sendSlotContents(Container container, int slot, ItemStack stack)
{
if(stack != null && stack.stackSize > Byte.MAX_VALUE)
public void sendSlotContents(Container container, int slot, ItemStack stack) {
if (stack != null && stack.stackSize > Byte.MAX_VALUE)
sendLargeStack(stack, slot, playerCrafters);
else
for(EntityPlayerMP player : playerCrafters)
for (EntityPlayerMP player : playerCrafters)
player.sendSlotContents(container, slot, stack);
}
@Override
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer player)
{
if(par1 >= 0 && par1 < inventorySlots.size())
{
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer player) {
if (par1 >= 0 && par1 < inventorySlots.size()) {
Slot slot = getSlot(par1);
if(slot instanceof SlotHandleClicks)
if (slot instanceof SlotHandleClicks)
return ((SlotHandleClicks) slot).slotClick(this, player, par2, par3);
}
return super.slotClick(par1, par2, par3, player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex)
{
ItemStack transferredStack = null;
Slot slot = (Slot)inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack())
{
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
ItemStack transferredStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
transferredStack = stack.copy();
if(!doMergeStackAreas(slotIndex, stack))
if (!doMergeStackAreas(slotIndex, stack))
return null;
if (stack.stackSize == 0)
@@ -131,45 +113,39 @@ public abstract class ContainerExtended extends Container implements ICrafting
return transferredStack;
}
@Override
public boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverse)
{
public boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverse) {
boolean merged = false;
int slotIndex = reverse ? endIndex - 1 : startIndex;
if(stack == null)
if (stack == null)
return false;
if (stack.isStackable())//search for stacks to increase
{
while (stack.stackSize > 0 && (reverse ? slotIndex >= startIndex : slotIndex < endIndex))
{
Slot slot = (Slot)inventorySlots.get(slotIndex);
while (stack.stackSize > 0 && (reverse ? slotIndex >= startIndex : slotIndex < endIndex)) {
Slot slot = (Slot) inventorySlots.get(slotIndex);
ItemStack slotStack = slot.getStack();
if (slotStack != null && slotStack.getItem() == stack.getItem() &&
(!stack.getHasSubtypes() || stack.getItemDamage() == slotStack.getItemDamage()) &&
ItemStack.areItemStackTagsEqual(stack, slotStack))
{
(!stack.getHasSubtypes() || stack.getItemDamage() == slotStack.getItemDamage()) &&
ItemStack.areItemStackTagsEqual(stack, slotStack)) {
int totalStackSize = slotStack.stackSize + stack.stackSize;
int maxStackSize = Math.min(stack.getMaxStackSize(), slot.getSlotStackLimit());
if (totalStackSize <= maxStackSize)
{
if (totalStackSize <= maxStackSize) {
stack.stackSize = 0;
slotStack.stackSize = totalStackSize;
slot.onSlotChanged();
merged = true;
}
else if (slotStack.stackSize < maxStackSize)
{
} else if (slotStack.stackSize < maxStackSize) {
stack.stackSize -= maxStackSize - slotStack.stackSize;
slotStack.stackSize = maxStackSize;
slot.onSlotChanged();
merged = true;
}
}
slotIndex += reverse ? -1 : 1;
}
}
@@ -178,28 +154,23 @@ public abstract class ContainerExtended extends Container implements ICrafting
{
slotIndex = reverse ? endIndex - 1 : startIndex;
while (stack.stackSize > 0 && (reverse ? slotIndex >= startIndex : slotIndex < endIndex))
{
Slot slot = (Slot)this.inventorySlots.get(slotIndex);
if (!slot.getHasStack() && slot.isItemValid(stack))
{
while (stack.stackSize > 0 && (reverse ? slotIndex >= startIndex : slotIndex < endIndex)) {
Slot slot = (Slot) this.inventorySlots.get(slotIndex);
if (!slot.getHasStack() && slot.isItemValid(stack)) {
int maxStackSize = Math.min(stack.getMaxStackSize(), slot.getSlotStackLimit());
if (stack.stackSize <= maxStackSize)
{
if (stack.stackSize <= maxStackSize) {
slot.putStack(stack.copy());
slot.onSlotChanged();
stack.stackSize = 0;
merged = true;
}
else
{
} else {
slot.putStack(stack.splitStack(maxStackSize));
slot.onSlotChanged();
merged = true;
}
}
slotIndex += reverse ? -1 : 1;
}
}
@@ -207,61 +178,58 @@ public abstract class ContainerExtended extends Container implements ICrafting
return merged;
}
public boolean doMergeStackAreas(int slotIndex, ItemStack stack)
{
/**
* Called when slotIndex is shift clicked on. Recommended implementation is to call mergeItemStack based on slotIndex
*
* @param stack The stack in the clicked slot
* @return True if one or more items were moved from this slots into other slots
*/
public boolean doMergeStackAreas(int slotIndex, ItemStack stack) {
return false;
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
{
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
bindPlayerInventory(inventoryPlayer, 8, 84);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer, int x, int y)
{
for(int row = 0; row < 3; row++)
for(int col = 0; col < 9; col++)
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer, int x, int y) {
for (int row = 0; row < 3; row++)
for (int col = 0; col < 9; col++)
addSlotToContainer(new Slot(inventoryPlayer, col + row * 9 + 9, x + col * 18, y + row * 18));
for(int slot = 0; slot < 9; slot++)
for (int slot = 0; slot < 9; slot++)
addSlotToContainer(new Slot(inventoryPlayer, slot, x + slot * 18, y + 58));
}
@Override
public boolean canInteractWith(EntityPlayer var1)
{
public boolean canInteractWith(EntityPlayer var1) {
return true;
}
public void sendContainerPacket(PacketCustom packet)
{
for(EntityPlayerMP player : playerCrafters)
public void sendContainerPacket(PacketCustom packet) {
for (EntityPlayerMP player : playerCrafters)
packet.sendToPlayer(player);
}
/**
* May be called from a client packet handler to handle additional info
*/
public void handleOutputPacket(PacketCustom packet)
{
public void handleOutputPacket(PacketCustom packet) {
}
/**
* May be called from a server packet handler to handle additional info
*/
public void handleInputPacket(PacketCustom packet)
{
public void handleInputPacket(PacketCustom packet) {
}
/**
* May be called from a server packet handler to handle client input
*/
public void handleGuiChange(int ID, int value)
{
public void handleGuiChange(int ID, int value) {
}
public void sendProgressBarUpdate(int barID, int value)
{
for(ICrafting crafting : (List<ICrafting>)crafters)
public void sendProgressBarUpdate(int barID, int value) {
for (ICrafting crafting : (List<ICrafting>) crafters)
crafting.sendProgressBarUpdate(this, barID, value);
}
}