Reformatted all the code using the default intelji formatting options.
This commit is contained in:
parent
2f63a24070
commit
e0ab0af822
363 changed files with 20524 additions and 23016 deletions
|
@ -13,41 +13,37 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class BucketHandler {
|
||||
|
||||
public static BucketHandler INSTANCE = new BucketHandler();
|
||||
public Map<Block, Item> buckets = new HashMap<Block, Item>();
|
||||
|
||||
private BucketHandler()
|
||||
{
|
||||
|
||||
}
|
||||
public static BucketHandler INSTANCE = new BucketHandler();
|
||||
public Map<Block, Item> buckets = new HashMap<Block, Item>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBucketFill(FillBucketEvent event)
|
||||
{
|
||||
ItemStack result = fillCustomBucket(event.world, event.target);
|
||||
private BucketHandler() {
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
}
|
||||
|
||||
event.result = result;
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onBucketFill(FillBucketEvent event) {
|
||||
ItemStack result = fillCustomBucket(event.world, event.target);
|
||||
|
||||
private ItemStack fillCustomBucket(World world, MovingObjectPosition pos)
|
||||
{
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
|
||||
event.result = result;
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
|
||||
Item bucket = buckets.get(block);
|
||||
if (bucket != null
|
||||
&& world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0)
|
||||
{
|
||||
world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
|
||||
return new ItemStack(bucket);
|
||||
} else
|
||||
return null;
|
||||
private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {
|
||||
|
||||
}
|
||||
Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
|
||||
|
||||
Item bucket = buckets.get(block);
|
||||
if (bucket != null
|
||||
&& world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {
|
||||
world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
|
||||
return new ItemStack(bucket);
|
||||
} else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,42 +4,41 @@ package techreborn.util;
|
|||
* @author TeamC4
|
||||
*/
|
||||
|
||||
public enum Color
|
||||
{
|
||||
BLACK("\u00A70"), //
|
||||
DARK_BLUE("\u00A71"), //
|
||||
DARK_GREEN("\u00A72"), //
|
||||
DARK_AQUA("\u00A73"), //
|
||||
DARK_RED("\u00A74"), //
|
||||
DARK_PURPLE("\u00A75"), //
|
||||
GOLD("\u00A76"), //
|
||||
GRAY("\u00A77"), //
|
||||
DARK_GRAY("\u00A78"), //
|
||||
BLUE("\u00A79"), //
|
||||
GREEN("\u00A7a"), //
|
||||
AQUA("\u00A7b"), //
|
||||
RED("\u00A7c"), //
|
||||
LIGHT_PURPLE("\u00A7d"), //
|
||||
YELLOW("\u00A7e"), //
|
||||
WHITE("\u00A7f"), //
|
||||
public enum Color {
|
||||
BLACK("\u00A70"), //
|
||||
DARK_BLUE("\u00A71"), //
|
||||
DARK_GREEN("\u00A72"), //
|
||||
DARK_AQUA("\u00A73"), //
|
||||
DARK_RED("\u00A74"), //
|
||||
DARK_PURPLE("\u00A75"), //
|
||||
GOLD("\u00A76"), //
|
||||
GRAY("\u00A77"), //
|
||||
DARK_GRAY("\u00A78"), //
|
||||
BLUE("\u00A79"), //
|
||||
GREEN("\u00A7a"), //
|
||||
AQUA("\u00A7b"), //
|
||||
RED("\u00A7c"), //
|
||||
LIGHT_PURPLE("\u00A7d"), //
|
||||
YELLOW("\u00A7e"), //
|
||||
WHITE("\u00A7f"), //
|
||||
|
||||
STRIKE_THROUGH("\u00A7m"), //
|
||||
UNDERLINE("\u00A7n"), //
|
||||
BOLD("\u00A7l"), //
|
||||
RANDOM("\u00A7k"), //
|
||||
ITALIC("\u00A7o"), //
|
||||
RESET("\u00A7r"); //
|
||||
STRIKE_THROUGH("\u00A7m"), //
|
||||
UNDERLINE("\u00A7n"), //
|
||||
BOLD("\u00A7l"), //
|
||||
RANDOM("\u00A7k"), //
|
||||
ITALIC("\u00A7o"), //
|
||||
RESET("\u00A7r"); //
|
||||
|
||||
public String code = "";
|
||||
public String code = "";
|
||||
|
||||
private Color(String code) {
|
||||
private Color(String code) {
|
||||
|
||||
this.code = code;
|
||||
}
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,18 +7,16 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
|||
|
||||
public class CraftingHelper {
|
||||
|
||||
public static void addShapedOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapedOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
public static void addShapedOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs) {
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapedOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
|
||||
public static void addShapelessOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapelessOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
public static void addShapelessOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs) {
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapelessOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,64 +10,64 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
|
||||
public class FluidUtils {
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
|
||||
if (input != null) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(output, emptyItem, true, true)))) {
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used >= fluidInContainer.amount && fluidHandler.canFill(ForgeDirection.UP, fluidInContainer.getFluid())) {
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (emptyItem != null)
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (input != null) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(output, emptyItem, true, true)))) {
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used >= fluidInContainer.amount && fluidHandler.canFill(ForgeDirection.UP, fluidInContainer.getFluid())) {
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (emptyItem != null)
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean fillContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(filled, output, true, true)))) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN,
|
||||
fluidInContainer, false);
|
||||
if (drain != null && drain.amount == fluidInContainer.amount) {
|
||||
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, filled);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean fillContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(filled, output, true, true)))) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN,
|
||||
fluidInContainer, false);
|
||||
if (drain != null && drain.amount == fluidInContainer.amount) {
|
||||
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, filled);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static FluidStack getFluidStackInContainer(ItemStack stack) {
|
||||
return FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
}
|
||||
public static FluidStack getFluidStackInContainer(ItemStack stack) {
|
||||
return FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
}
|
||||
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
if (fluid == null || empty == null)
|
||||
return null;
|
||||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid,
|
||||
Integer.MAX_VALUE), empty);
|
||||
}
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
if (fluid == null || empty == null)
|
||||
return null;
|
||||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid,
|
||||
Integer.MAX_VALUE), empty);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,186 +10,155 @@ import net.minecraftforge.common.util.Constants;
|
|||
|
||||
public class Inventory implements IInventory {
|
||||
|
||||
private final ItemStack[] contents;
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
private TileEntity tile = new TileEntity();
|
||||
public boolean hasChanged = false;
|
||||
private final ItemStack[] contents;
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
private TileEntity tile = new TileEntity();
|
||||
public boolean hasChanged = false;
|
||||
|
||||
public Inventory(int size, String invName, int invStackLimit)
|
||||
{
|
||||
contents = new ItemStack[size];
|
||||
name = invName;
|
||||
stackLimit = invStackLimit;
|
||||
}
|
||||
public Inventory(int size, String invName, int invStackLimit) {
|
||||
contents = new ItemStack[size];
|
||||
name = invName;
|
||||
stackLimit = invStackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return contents.length;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return contents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId)
|
||||
{
|
||||
return contents[slotId];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId) {
|
||||
return contents[slotId];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count)
|
||||
{
|
||||
if (slotId < contents.length && contents[slotId] != null)
|
||||
{
|
||||
if (contents[slotId].stackSize > count)
|
||||
{
|
||||
ItemStack result = contents[slotId].splitStack(count);
|
||||
markDirty();
|
||||
hasChanged = true;
|
||||
return result;
|
||||
}
|
||||
ItemStack stack = contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
hasChanged = true;
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
if (slotId < contents.length && contents[slotId] != null) {
|
||||
if (contents[slotId].stackSize > count) {
|
||||
ItemStack result = contents[slotId].splitStack(count);
|
||||
markDirty();
|
||||
hasChanged = true;
|
||||
return result;
|
||||
}
|
||||
ItemStack stack = contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
hasChanged = true;
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack)
|
||||
{
|
||||
if (slotId >= contents.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
contents[slotId] = itemstack;
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack) {
|
||||
if (slotId >= contents.length) {
|
||||
return;
|
||||
}
|
||||
contents[slotId] = itemstack;
|
||||
|
||||
if (itemstack != null
|
||||
&& itemstack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
hasChanged = true;
|
||||
}
|
||||
if (itemstack != null
|
||||
&& itemstack.stackSize > this.getInventoryStackLimit()) {
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return stackLimit;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return stackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
readFromNBT(data, "Items");
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
readFromNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagList nbttaglist = data
|
||||
.getTagList(tag, Constants.NBT.TAG_COMPOUND);
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList nbttaglist = data
|
||||
.getTagList(tag, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
{
|
||||
NBTTagCompound slot = nbttaglist.getCompoundTagAt(j);
|
||||
int index;
|
||||
if (slot.hasKey("index"))
|
||||
{
|
||||
index = slot.getInteger("index");
|
||||
} else
|
||||
{
|
||||
index = slot.getByte("Slot");
|
||||
}
|
||||
if (index >= 0 && index < contents.length)
|
||||
{
|
||||
setInventorySlotContents(index,
|
||||
ItemStack.loadItemStackFromNBT(slot));
|
||||
}
|
||||
}
|
||||
hasChanged = true;
|
||||
}
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
NBTTagCompound slot = nbttaglist.getCompoundTagAt(j);
|
||||
int index;
|
||||
if (slot.hasKey("index")) {
|
||||
index = slot.getInteger("index");
|
||||
} else {
|
||||
index = slot.getByte("Slot");
|
||||
}
|
||||
if (index >= 0 && index < contents.length) {
|
||||
setInventorySlotContents(index,
|
||||
ItemStack.loadItemStackFromNBT(slot));
|
||||
}
|
||||
}
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
writeToNBT(data, "Items");
|
||||
}
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
writeToNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (byte index = 0; index < contents.length; ++index)
|
||||
{
|
||||
if (contents[index] != null && contents[index].stackSize > 0)
|
||||
{
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
slots.appendTag(slot);
|
||||
slot.setByte("Slot", index);
|
||||
contents[index].writeToNBT(slot);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, slots);
|
||||
}
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (byte index = 0; index < contents.length; ++index) {
|
||||
if (contents[index] != null && contents[index].stackSize > 0) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
slots.appendTag(slot);
|
||||
slot.setByte("Slot", index);
|
||||
contents[index].writeToNBT(slot);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, slots);
|
||||
}
|
||||
|
||||
public void setTile(TileEntity tileEntity)
|
||||
{
|
||||
tile = tileEntity;
|
||||
}
|
||||
public void setTile(TileEntity tileEntity) {
|
||||
tile = tileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId)
|
||||
{
|
||||
if (this.contents[slotId] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId) {
|
||||
if (this.contents[slotId] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack stackToTake = this.contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stackToTake;
|
||||
}
|
||||
ItemStack stackToTake = this.contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stackToTake;
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
public ItemStack[] getStacks() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
tile.markDirty();
|
||||
}
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tile.markDirty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,119 +14,106 @@ import java.util.List;
|
|||
*/
|
||||
public class ItemUtils {
|
||||
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b,
|
||||
final boolean matchDamage, final boolean matchNBT)
|
||||
{
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes())
|
||||
{
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b,
|
||||
final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isItemEqual(ItemStack a, ItemStack b,
|
||||
boolean matchDamage, boolean matchNBT, boolean useOreDic)
|
||||
{
|
||||
if(isItemEqual(a, b, matchDamage, matchNBT)){
|
||||
return true;
|
||||
}
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if(useOreDic){
|
||||
for (int inta : OreDictionary.getOreIDs(a)){
|
||||
for (int intb : OreDictionary.getOreIDs(b)){
|
||||
if(inta == intb){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean isItemEqual(ItemStack a, ItemStack b,
|
||||
boolean matchDamage, boolean matchNBT, boolean useOreDic) {
|
||||
if (isItemEqual(a, b, matchDamage, matchNBT)) {
|
||||
return true;
|
||||
}
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (useOreDic) {
|
||||
for (int inta : OreDictionary.getOreIDs(a)) {
|
||||
for (int intb : OreDictionary.getOreIDs(b)) {
|
||||
if (inta == intb) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isWildcard(ItemStack stack)
|
||||
{
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
|
||||
public static boolean isWildcard(int damage)
|
||||
{
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public static void writeInvToNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data)
|
||||
{
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (byte slot = 0; slot < inv.getSizeInventory(); slot++)
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if (stack != null)
|
||||
{
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", slot);
|
||||
writeItemToNBT(stack, itemTag);
|
||||
list.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, list);
|
||||
}
|
||||
public static void writeInvToNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (byte slot = 0; slot < inv.getSizeInventory(); slot++) {
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", slot);
|
||||
writeItemToNBT(stack, itemTag);
|
||||
list.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, list);
|
||||
}
|
||||
|
||||
public static void readInvFromNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data)
|
||||
{
|
||||
NBTTagList list = data.getTagList(tag, 10);
|
||||
for (byte entry = 0; entry < list.tagCount(); entry++)
|
||||
{
|
||||
NBTTagCompound itemTag = list.getCompoundTagAt(entry);
|
||||
int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.getSizeInventory())
|
||||
{
|
||||
ItemStack stack = readItemFromNBT(itemTag);
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void readInvFromNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data) {
|
||||
NBTTagList list = data.getTagList(tag, 10);
|
||||
for (byte entry = 0; entry < list.tagCount(); entry++) {
|
||||
NBTTagCompound itemTag = list.getCompoundTagAt(entry);
|
||||
int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.getSizeInventory()) {
|
||||
ItemStack stack = readItemFromNBT(itemTag);
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeItemToNBT(ItemStack stack, NBTTagCompound data)
|
||||
{
|
||||
if (stack == null || stack.stackSize <= 0)
|
||||
return;
|
||||
if (stack.stackSize > 127)
|
||||
stack.stackSize = 127;
|
||||
stack.writeToNBT(data);
|
||||
}
|
||||
public static void writeItemToNBT(ItemStack stack, NBTTagCompound data) {
|
||||
if (stack == null || stack.stackSize <= 0)
|
||||
return;
|
||||
if (stack.stackSize > 127)
|
||||
stack.stackSize = 127;
|
||||
stack.writeToNBT(data);
|
||||
}
|
||||
|
||||
public static ItemStack readItemFromNBT(NBTTagCompound data)
|
||||
{
|
||||
return ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
public static ItemStack readItemFromNBT(NBTTagCompound data) {
|
||||
return ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
|
||||
public static List<ItemStack> getStackWithAllOre(ItemStack stack){
|
||||
if(stack == null){
|
||||
public static List<ItemStack> getStackWithAllOre(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
for (int oreID : OreDictionary.getOreIDs(stack)){
|
||||
for(ItemStack ore : OreDictionary.getOres(OreDictionary.getOreName(oreID))){
|
||||
ItemStack newOre = ore;
|
||||
newOre.stackSize = stack.stackSize;
|
||||
list.add(newOre);
|
||||
}
|
||||
}
|
||||
if(list.isEmpty()){
|
||||
list.add(stack);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
for (int oreID : OreDictionary.getOreIDs(stack)) {
|
||||
for (ItemStack ore : OreDictionary.getOres(OreDictionary.getOreName(oreID))) {
|
||||
ItemStack newOre = ore;
|
||||
newOre.stackSize = stack.stackSize;
|
||||
list.add(newOre);
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
list.add(stack);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,49 +6,40 @@ import techreborn.lib.ModInfo;
|
|||
|
||||
public class LogHelper {
|
||||
|
||||
public static void log(Level logLevel, Object object)
|
||||
{
|
||||
FMLLog.log(ModInfo.MOD_NAME, logLevel, String.valueOf(object));
|
||||
}
|
||||
public static void log(Level logLevel, Object object) {
|
||||
FMLLog.log(ModInfo.MOD_NAME, logLevel, String.valueOf(object));
|
||||
}
|
||||
|
||||
public static void all(Object object)
|
||||
{
|
||||
log(Level.ALL, object);
|
||||
}
|
||||
public static void all(Object object) {
|
||||
log(Level.ALL, object);
|
||||
}
|
||||
|
||||
public static void debug(Object object)
|
||||
{
|
||||
log(Level.DEBUG, object);
|
||||
}
|
||||
public static void debug(Object object) {
|
||||
log(Level.DEBUG, object);
|
||||
}
|
||||
|
||||
public static void error(Object object)
|
||||
{
|
||||
log(Level.ERROR, object);
|
||||
}
|
||||
public static void error(Object object) {
|
||||
log(Level.ERROR, object);
|
||||
}
|
||||
|
||||
public static void fatal(Object object)
|
||||
{
|
||||
log(Level.FATAL, object);
|
||||
}
|
||||
public static void fatal(Object object) {
|
||||
log(Level.FATAL, object);
|
||||
}
|
||||
|
||||
public static void info(Object object)
|
||||
{
|
||||
log(Level.INFO, object);
|
||||
}
|
||||
public static void info(Object object) {
|
||||
log(Level.INFO, object);
|
||||
}
|
||||
|
||||
public static void off(Object object)
|
||||
{
|
||||
log(Level.OFF, object);
|
||||
}
|
||||
public static void off(Object object) {
|
||||
log(Level.OFF, object);
|
||||
}
|
||||
|
||||
public static void trace(Object object)
|
||||
{
|
||||
log(Level.TRACE, object);
|
||||
}
|
||||
public static void trace(Object object) {
|
||||
log(Level.TRACE, object);
|
||||
}
|
||||
|
||||
public static void warn(Object object)
|
||||
{
|
||||
log(Level.WARN, object);
|
||||
}
|
||||
public static void warn(Object object) {
|
||||
log(Level.WARN, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,66 +6,56 @@ import techreborn.config.ConfigTechReborn;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
public class OreDrop
|
||||
{
|
||||
public OreDrop(ItemStack drop)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.count = drop.stackSize;
|
||||
this.baseChance = 100;
|
||||
}
|
||||
public class OreDrop {
|
||||
public OreDrop(ItemStack drop) {
|
||||
this.drop = drop;
|
||||
this.count = drop.stackSize;
|
||||
this.baseChance = 100;
|
||||
}
|
||||
|
||||
public OreDrop(ItemStack drop, double baseChance)
|
||||
{
|
||||
this.drop = drop;
|
||||
this.count = drop.stackSize;
|
||||
this.baseChance = (int)(baseChance * 100);
|
||||
}
|
||||
|
||||
public ItemStack getDrops(int fortuneLevel, Random random)
|
||||
{
|
||||
int count;
|
||||
if (baseChance == 100) //This always drops. Use vanilla fortune rules.
|
||||
{
|
||||
count = calculateFortuneMulti(fortuneLevel, random);
|
||||
} else if (calculateFortuneSingle(fortuneLevel, random)) //This has a chance to drop. Increase that chance with fortune.
|
||||
{
|
||||
count = this.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
return new ItemStack(drop.getItem(), count, drop.getItemDamage());
|
||||
}
|
||||
|
||||
//Refer to http://minecraft.gamepedia.com/Enchanting#Fortune
|
||||
private int calculateFortuneMulti(int level, Random random)
|
||||
{
|
||||
int chanceOfEachBonus = 100 / (level + 2);
|
||||
int roll = random.nextInt(100);
|
||||
|
||||
if (roll < chanceOfEachBonus * level) //If level = 0, this is always false
|
||||
{
|
||||
return count * ((roll / chanceOfEachBonus) + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
//Each fortune level increases probability by 50% (configurable) of base, up to a limit of 100%, obviously.
|
||||
//So, if base is 5% and we have Fortune III, chance is 5% + (3 * 2.5%) = 12.5%
|
||||
private boolean calculateFortuneSingle(int level, Random random)
|
||||
{
|
||||
double modifier = ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel * level;
|
||||
double total = baseChance + (baseChance * modifier);
|
||||
int roll = random.nextInt(100);
|
||||
return roll <= total;
|
||||
}
|
||||
|
||||
public ItemStack drop;
|
||||
public Integer baseChance;
|
||||
public Integer count;
|
||||
public OreDrop(ItemStack drop, double baseChance) {
|
||||
this.drop = drop;
|
||||
this.count = drop.stackSize;
|
||||
this.baseChance = (int) (baseChance * 100);
|
||||
}
|
||||
|
||||
public ItemStack getDrops(int fortuneLevel, Random random) {
|
||||
int count;
|
||||
if (baseChance == 100) //This always drops. Use vanilla fortune rules.
|
||||
{
|
||||
count = calculateFortuneMulti(fortuneLevel, random);
|
||||
} else if (calculateFortuneSingle(fortuneLevel, random)) //This has a chance to drop. Increase that chance with fortune.
|
||||
{
|
||||
count = this.count;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
return new ItemStack(drop.getItem(), count, drop.getItemDamage());
|
||||
}
|
||||
|
||||
//Refer to http://minecraft.gamepedia.com/Enchanting#Fortune
|
||||
private int calculateFortuneMulti(int level, Random random) {
|
||||
int chanceOfEachBonus = 100 / (level + 2);
|
||||
int roll = random.nextInt(100);
|
||||
|
||||
if (roll < chanceOfEachBonus * level) //If level = 0, this is always false
|
||||
{
|
||||
return count * ((roll / chanceOfEachBonus) + 2);
|
||||
} else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
//Each fortune level increases probability by 50% (configurable) of base, up to a limit of 100%, obviously.
|
||||
//So, if base is 5% and we have Fortune III, chance is 5% + (3 * 2.5%) = 12.5%
|
||||
private boolean calculateFortuneSingle(int level, Random random) {
|
||||
double modifier = ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel * level;
|
||||
double total = baseChance + (baseChance * modifier);
|
||||
int roll = random.nextInt(100);
|
||||
return roll <= total;
|
||||
}
|
||||
|
||||
public ItemStack drop;
|
||||
public Integer baseChance;
|
||||
public Integer count;
|
||||
}
|
|
@ -5,24 +5,20 @@ import net.minecraft.item.ItemStack;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class OreDropSet
|
||||
{
|
||||
public OreDropSet(OreDrop... oreDrops)
|
||||
{
|
||||
this.dropSet = oreDrops;
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> drop(int fortune, Random random)
|
||||
{
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
public class OreDropSet {
|
||||
public OreDropSet(OreDrop... oreDrops) {
|
||||
this.dropSet = oreDrops;
|
||||
}
|
||||
|
||||
for (OreDrop drop : dropSet)
|
||||
{
|
||||
drops.add(drop.getDrops(fortune, random));
|
||||
}
|
||||
public ArrayList<ItemStack> drop(int fortune, Random random) {
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
|
||||
return drops;
|
||||
}
|
||||
for (OreDrop drop : dropSet) {
|
||||
drops.add(drop.getDrops(fortune, random));
|
||||
}
|
||||
|
||||
public OreDrop[] dropSet;
|
||||
return drops;
|
||||
}
|
||||
|
||||
public OreDrop[] dropSet;
|
||||
}
|
|
@ -8,42 +8,34 @@ import net.minecraft.item.crafting.ShapedRecipes;
|
|||
import java.util.List;
|
||||
|
||||
public class RecipeRemover {
|
||||
public static void removeShapedRecipes(List<ItemStack> removelist)
|
||||
{
|
||||
for (ItemStack stack : removelist)
|
||||
removeShapedRecipe(stack);
|
||||
}
|
||||
public static void removeShapedRecipes(List<ItemStack> removelist) {
|
||||
for (ItemStack stack : removelist)
|
||||
removeShapedRecipe(stack);
|
||||
}
|
||||
|
||||
public static void removeAnyRecipe(ItemStack resultItem)
|
||||
{
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++)
|
||||
{
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
ItemStack recipeResult = tmpRecipe.getRecipeOutput();
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
|
||||
{
|
||||
recipes.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void removeAnyRecipe(ItemStack resultItem) {
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
ItemStack recipeResult = tmpRecipe.getRecipeOutput();
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
|
||||
recipes.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeShapedRecipe(ItemStack resultItem)
|
||||
{
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++)
|
||||
{
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
if (tmpRecipe instanceof ShapedRecipes)
|
||||
{
|
||||
ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
|
||||
ItemStack recipeResult = recipe.getRecipeOutput();
|
||||
public static void removeShapedRecipe(ItemStack resultItem) {
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
if (tmpRecipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
|
||||
ItemStack recipeResult = recipe.getRecipeOutput();
|
||||
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
|
||||
{
|
||||
recipes.remove(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
|
||||
recipes.remove(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,80 +9,70 @@ import techreborn.packets.PacketHandler;
|
|||
|
||||
public class Tank extends FluidTank {
|
||||
|
||||
private final String name;
|
||||
private final String name;
|
||||
|
||||
private FluidStack lastBeforeUpdate = null;
|
||||
private FluidStack lastBeforeUpdate = null;
|
||||
|
||||
public Tank(String name, int capacity, TileEntity tile)
|
||||
{
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
this.tile = tile;
|
||||
}
|
||||
public Tank(String name, int capacity, TileEntity tile) {
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
public boolean isEmpty() {
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
|
||||
public boolean isFull()
|
||||
{
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
public boolean isFull() {
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
|
||||
public Fluid getFluidType()
|
||||
{
|
||||
return getFluid() != null ? getFluid().getFluid() : null;
|
||||
}
|
||||
public Fluid getFluidType() {
|
||||
return getFluid() != null ? getFluid().getFluid() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
@Override
|
||||
public final NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FluidTank readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt.hasKey(name))
|
||||
{
|
||||
// allow to read empty tanks
|
||||
setFluid(null);
|
||||
@Override
|
||||
public final FluidTank readFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(name)) {
|
||||
// allow to read empty tanks
|
||||
setFluid(null);
|
||||
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void compareAndUpdate() {
|
||||
if(tile.getWorldObj().isRemote){
|
||||
return;
|
||||
}
|
||||
FluidStack current = this.getFluid();
|
||||
if (current != null) {
|
||||
if (lastBeforeUpdate != null) {
|
||||
if (Math.abs(current.amount - lastBeforeUpdate.amount) >= 500) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
else if (lastBeforeUpdate.amount < this.getCapacity() && current.amount == this.getCapacity() || lastBeforeUpdate.amount == this.getCapacity() && current.amount < this.getCapacity()) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
}
|
||||
else {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
}
|
||||
else if (lastBeforeUpdate != null) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = null;
|
||||
}
|
||||
}
|
||||
public void compareAndUpdate() {
|
||||
if (tile.getWorldObj().isRemote) {
|
||||
return;
|
||||
}
|
||||
FluidStack current = this.getFluid();
|
||||
if (current != null) {
|
||||
if (lastBeforeUpdate != null) {
|
||||
if (Math.abs(current.amount - lastBeforeUpdate.amount) >= 500) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
} else if (lastBeforeUpdate.amount < this.getCapacity() && current.amount == this.getCapacity() || lastBeforeUpdate.amount == this.getCapacity() && current.amount < this.getCapacity()) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
} else {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = current.copy();
|
||||
}
|
||||
} else if (lastBeforeUpdate != null) {
|
||||
PacketHandler.sendPacketToAllPlayers(tile.getDescriptionPacket(), tile.getWorldObj());
|
||||
lastBeforeUpdate = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,36 +9,32 @@ import net.minecraftforge.event.ForgeEventFactory;
|
|||
|
||||
public class TorchHelper {
|
||||
|
||||
public static boolean placeTorch(ItemStack stack, EntityPlayer player,
|
||||
World world, int x, int y, int z, int side, float xOffset,
|
||||
float yOffset, float zOffset)
|
||||
{
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++)
|
||||
{
|
||||
ItemStack torchStack = player.inventory.mainInventory[i];
|
||||
if (torchStack == null
|
||||
|| !torchStack.getUnlocalizedName().toLowerCase()
|
||||
.contains("torch"))
|
||||
continue;
|
||||
Item item = torchStack.getItem();
|
||||
if (!(item instanceof ItemBlock))
|
||||
continue;
|
||||
int oldMeta = torchStack.getItemDamage();
|
||||
int oldSize = torchStack.stackSize;
|
||||
boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x,
|
||||
y, z, side, xOffset, yOffset, zOffset);
|
||||
if (player.capabilities.isCreativeMode)
|
||||
{
|
||||
torchStack.setItemDamage(oldMeta);
|
||||
torchStack.stackSize = oldSize;
|
||||
} else if (torchStack.stackSize <= 0)
|
||||
{
|
||||
ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
|
||||
player.inventory.mainInventory[i] = null;
|
||||
}
|
||||
if (result)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean placeTorch(ItemStack stack, EntityPlayer player,
|
||||
World world, int x, int y, int z, int side, float xOffset,
|
||||
float yOffset, float zOffset) {
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack torchStack = player.inventory.mainInventory[i];
|
||||
if (torchStack == null
|
||||
|| !torchStack.getUnlocalizedName().toLowerCase()
|
||||
.contains("torch"))
|
||||
continue;
|
||||
Item item = torchStack.getItem();
|
||||
if (!(item instanceof ItemBlock))
|
||||
continue;
|
||||
int oldMeta = torchStack.getItemDamage();
|
||||
int oldSize = torchStack.stackSize;
|
||||
boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x,
|
||||
y, z, side, xOffset, yOffset, zOffset);
|
||||
if (player.capabilities.isCreativeMode) {
|
||||
torchStack.setItemDamage(oldMeta);
|
||||
torchStack.stackSize = oldSize;
|
||||
} else if (torchStack.stackSize <= 0) {
|
||||
ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
|
||||
player.inventory.mainInventory[i] = null;
|
||||
}
|
||||
if (result)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,116 +16,117 @@ import java.util.ArrayList;
|
|||
|
||||
public class VersionChecker {
|
||||
|
||||
public static final String apiAddress = "http://modmuss50.me/api/v1/version.php";
|
||||
public static final String apiAddress = "http://modmuss50.me/api/v1/version.php";
|
||||
|
||||
public String projectName;
|
||||
public String projectName;
|
||||
|
||||
ArrayList<ModifacationVersionInfo> versions;
|
||||
ArrayList<ModifacationVersionInfo> versions;
|
||||
|
||||
public boolean isChecking;
|
||||
public boolean isChecking;
|
||||
|
||||
public VersionChecker(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
public VersionChecker(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public void checkVersion() throws IOException {
|
||||
isChecking = true;
|
||||
URL url = new URL(apiAddress + "?project=" + projectName);
|
||||
URLConnection con = url.openConnection();
|
||||
InputStream in = con.getInputStream();
|
||||
String encoding = con.getContentEncoding();
|
||||
encoding = encoding == null ? "UTF-8" : encoding;
|
||||
String body = IOUtils.toString(in, encoding).replaceAll("<br />", "");
|
||||
public void checkVersion() throws IOException {
|
||||
isChecking = true;
|
||||
URL url = new URL(apiAddress + "?project=" + projectName);
|
||||
URLConnection con = url.openConnection();
|
||||
InputStream in = con.getInputStream();
|
||||
String encoding = con.getContentEncoding();
|
||||
encoding = encoding == null ? "UTF-8" : encoding;
|
||||
String body = IOUtils.toString(in, encoding).replaceAll("<br />", "");
|
||||
|
||||
Gson gson = new Gson();
|
||||
versions = gson.fromJson(body,new TypeToken<ArrayList<ModifacationVersionInfo>>(){}.getType());
|
||||
isChecking = false;
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
versions = gson.fromJson(body, new TypeToken<ArrayList<ModifacationVersionInfo>>() {
|
||||
}.getType());
|
||||
isChecking = false;
|
||||
}
|
||||
|
||||
public void checkVersionThreaded(){
|
||||
class VersionCheckerThread extends Thread{
|
||||
public void run(){
|
||||
try {
|
||||
checkVersion();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
VersionCheckerThread thread = new VersionCheckerThread();
|
||||
thread.start();
|
||||
}
|
||||
public void checkVersionThreaded() {
|
||||
class VersionCheckerThread extends Thread {
|
||||
public void run() {
|
||||
try {
|
||||
checkVersion();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
VersionCheckerThread thread = new VersionCheckerThread();
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public boolean isLatestVersion(){
|
||||
if(versions == null || versions.isEmpty()){
|
||||
return true;
|
||||
}
|
||||
return versions.get(0).version.equals(ModInfo.MOD_VERSION);
|
||||
}
|
||||
public boolean isLatestVersion() {
|
||||
if (versions == null || versions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return versions.get(0).version.equals(ModInfo.MOD_VERSION);
|
||||
}
|
||||
|
||||
public ModifacationVersionInfo getLatestVersion(){
|
||||
if(versions == null || versions.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
return versions.get(0);
|
||||
}
|
||||
public ModifacationVersionInfo getLatestVersion() {
|
||||
if (versions == null || versions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return versions.get(0);
|
||||
}
|
||||
|
||||
public ArrayList<String> getChangeLogSinceCurrentVersion(){
|
||||
ArrayList<String> log = new ArrayList<String>();
|
||||
if(!isLatestVersion()){
|
||||
for(ModifacationVersionInfo version : versions){
|
||||
if(version.version.equals(ModInfo.MOD_VERSION)){
|
||||
break;
|
||||
}
|
||||
log.addAll(version.changeLog);
|
||||
}
|
||||
}
|
||||
return log;
|
||||
}
|
||||
public ArrayList<String> getChangeLogSinceCurrentVersion() {
|
||||
ArrayList<String> log = new ArrayList<String>();
|
||||
if (!isLatestVersion()) {
|
||||
for (ModifacationVersionInfo version : versions) {
|
||||
if (version.version.equals(ModInfo.MOD_VERSION)) {
|
||||
break;
|
||||
}
|
||||
log.addAll(version.changeLog);
|
||||
}
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
static class ModifacationVersionInfo{
|
||||
public String version;
|
||||
static class ModifacationVersionInfo {
|
||||
public String version;
|
||||
|
||||
public String minecraftVersion;
|
||||
public String minecraftVersion;
|
||||
|
||||
public ArrayList<String> changeLog;
|
||||
public ArrayList<String> changeLog;
|
||||
|
||||
public String releaseDate;
|
||||
public String releaseDate;
|
||||
|
||||
public boolean recommended;
|
||||
public boolean recommended;
|
||||
|
||||
public ModifacationVersionInfo(String version, String minecraftVersion, ArrayList<String> changeLog, String releaseDate, boolean recommended) {
|
||||
this.version = version;
|
||||
this.minecraftVersion = minecraftVersion;
|
||||
this.changeLog = changeLog;
|
||||
this.releaseDate = releaseDate;
|
||||
this.recommended = recommended;
|
||||
}
|
||||
public ModifacationVersionInfo(String version, String minecraftVersion, ArrayList<String> changeLog, String releaseDate, boolean recommended) {
|
||||
this.version = version;
|
||||
this.minecraftVersion = minecraftVersion;
|
||||
this.changeLog = changeLog;
|
||||
this.releaseDate = releaseDate;
|
||||
this.recommended = recommended;
|
||||
}
|
||||
|
||||
public ModifacationVersionInfo() {
|
||||
}
|
||||
}
|
||||
public ModifacationVersionInfo() {
|
||||
}
|
||||
}
|
||||
|
||||
//use this to make an example json file
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Generating example json file");
|
||||
ArrayList<ModifacationVersionInfo> infos = new ArrayList<ModifacationVersionInfo>();
|
||||
ArrayList<String> changelog = new ArrayList<String>();
|
||||
changelog.add("A change");
|
||||
changelog.add("Another change");
|
||||
//use this to make an example json file
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Generating example json file");
|
||||
ArrayList<ModifacationVersionInfo> infos = new ArrayList<ModifacationVersionInfo>();
|
||||
ArrayList<String> changelog = new ArrayList<String>();
|
||||
changelog.add("A change");
|
||||
changelog.add("Another change");
|
||||
|
||||
|
||||
infos.add(new ModifacationVersionInfo("1.1.1", "1.7.10", changelog, "12th July", true));
|
||||
infos.add(new ModifacationVersionInfo("1.2.0", "1.7.10", changelog, "28th July", true));
|
||||
infos.add(new ModifacationVersionInfo("1.1.1", "1.7.10", changelog, "12th July", true));
|
||||
infos.add(new ModifacationVersionInfo("1.2.0", "1.7.10", changelog, "28th July", true));
|
||||
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json = gson.toJson(infos);
|
||||
try {
|
||||
FileWriter writer = new FileWriter(new File("master.json"));
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json = gson.toJson(infos);
|
||||
try {
|
||||
FileWriter writer = new FileWriter(new File("master.json"));
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue