add pipe coloring/washing recipe, fix gate/docking station/etc. drops
This commit is contained in:
parent
0fd4ade49d
commit
c1c475fc65
6 changed files with 153 additions and 40 deletions
|
@ -109,6 +109,7 @@ import buildcraft.core.statements.TriggerInventoryLevel;
|
|||
import buildcraft.core.statements.TriggerMachine;
|
||||
import buildcraft.core.statements.TriggerRedstoneInput;
|
||||
import buildcraft.core.statements.ActionMachineControl.Mode;
|
||||
import buildcraft.core.utils.ColorUtils;
|
||||
import buildcraft.core.utils.CraftingHandler;
|
||||
import buildcraft.core.utils.WorldPropertyIsDirt;
|
||||
import buildcraft.core.utils.WorldPropertyIsFarmland;
|
||||
|
@ -402,6 +403,8 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
BuildCraftAPI.isShoveled = new WorldPropertyIsShoveled();
|
||||
BuildCraftAPI.isDirtProperty = new WorldPropertyIsDirt();
|
||||
BuildCraftAPI.isFluidSource = new WorldPropertyIsFluidSource();
|
||||
|
||||
ColorUtils.initialize();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -65,6 +65,7 @@ import buildcraft.transport.ItemPlug;
|
|||
import buildcraft.transport.ItemRobotStation;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.PipeActionProvider;
|
||||
import buildcraft.transport.PipeColoringRecipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTriggerProvider;
|
||||
import buildcraft.transport.TileFilteredBuffer;
|
||||
|
@ -525,6 +526,8 @@ public class BuildCraftTransport extends BuildCraftMod {
|
|||
}
|
||||
}
|
||||
|
||||
GameRegistry.addRecipe(new PipeColoringRecipe());
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(filteredBufferBlock, 1),
|
||||
"wdw", "wcw", "wpw", 'w', "plankWood", 'd',
|
||||
BuildCraftTransport.pipeItemsDiamond, 'c', Blocks.chest, 'p',
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
*/
|
||||
package buildcraft.core.utils;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public final class ColorUtils {
|
||||
|
||||
private static final int[] WOOL_TO_RGB = new int[] {
|
||||
|
@ -24,6 +28,15 @@ public final class ColorUtils {
|
|||
"brown", "green", "red", "black"
|
||||
};
|
||||
|
||||
private static final String[] OREDICT_DYE_NAMES = new String[] {
|
||||
"dyeWhite", "dyeOrange", "dyeMagenta", "dyeLightBlue",
|
||||
"dyeYellow", "dyeLime", "dyePink", "dyeGray",
|
||||
"dyeLightGray", "dyeCyan", "dyePurple", "dyeBlue",
|
||||
"dyeBrown", "dyeGreen", "dyeRed", "dyeBlack"
|
||||
};
|
||||
|
||||
private static final int[] OREDICT_DYE_IDS = new int[16];
|
||||
|
||||
private static final char[] WOOL_TO_CHAT = new char[] {
|
||||
'f', '6', 'd', '9', 'e', 'a', 'd', '8',
|
||||
'7', '3', '5', '1', '6', '2', '4', '0'
|
||||
|
@ -33,6 +46,33 @@ public final class ColorUtils {
|
|||
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
OREDICT_DYE_IDS[i] = OreDictionary.getOreID(OREDICT_DYE_NAMES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getColorIDFromDye(ItemStack stack) {
|
||||
if (stack.getItem() == Items.dye) {
|
||||
return 15 - stack.getItemDamage();
|
||||
}
|
||||
|
||||
int[] itemOreIDs = OreDictionary.getOreIDs(stack);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int id : itemOreIDs) {
|
||||
if (i == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean isDye(ItemStack stack) {
|
||||
return getColorIDFromDye(stack) >= 0;
|
||||
}
|
||||
|
||||
public static int getRGBColor(int wool) {
|
||||
return WOOL_TO_RGB[wool & 15];
|
||||
}
|
||||
|
|
|
@ -530,8 +530,6 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
return;
|
||||
}
|
||||
|
||||
pipe.onBlockRemoval();
|
||||
|
||||
World world = pipe.container.getWorldObj();
|
||||
|
||||
if (world == null) {
|
||||
|
@ -568,20 +566,17 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
}
|
||||
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
Pipe<?> pipe = getPipe(world, x, y, z);
|
||||
|
||||
int count = quantityDropped(metadata, fortune, world.rand);
|
||||
for (int i = 0; i < count; i++) {
|
||||
Pipe<?> pipe = getPipe(world, x, y, z);
|
||||
|
||||
if (pipe == null) {
|
||||
pipe = pipeRemoved.get(new BlockIndex(x, y, z));
|
||||
}
|
||||
|
||||
if (pipe != null) {
|
||||
if (pipe.item != null) {
|
||||
list.add(new ItemStack(pipe.item, 1, pipe.container.getItemMetadata()));
|
||||
list.addAll(pipe.getDroppedItems());
|
||||
}
|
||||
if (pipe == null) {
|
||||
pipe = pipeRemoved.get(new BlockIndex(x, y, z));
|
||||
}
|
||||
|
||||
if (pipe != null) {
|
||||
if (pipe.item != null) {
|
||||
list.add(new ItemStack(pipe.item, 1, pipe.container.getItemMetadata()));
|
||||
list.addAll(pipe.computeItemDrop());
|
||||
list.addAll(pipe.getDroppedItems());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
@ -597,26 +592,21 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
Pipe<?> pipe = getPipe(world, i, j, k);
|
||||
|
||||
int i1 = quantityDropped(world.rand);
|
||||
for (int j1 = 0; j1 < i1; j1++) {
|
||||
if (world.rand.nextFloat() > f) {
|
||||
continue;
|
||||
}
|
||||
if (pipe == null) {
|
||||
pipe = pipeRemoved.get(new BlockIndex(i, j, k));
|
||||
}
|
||||
|
||||
Pipe<?> pipe = getPipe(world, i, j, k);
|
||||
if (pipe != null) {
|
||||
Item k1 = pipe.item;
|
||||
|
||||
if (pipe == null) {
|
||||
pipe = pipeRemoved.get(new BlockIndex(i, j, k));
|
||||
}
|
||||
|
||||
if (pipe != null) {
|
||||
Item k1 = pipe.item;
|
||||
|
||||
if (k1 != null) {
|
||||
pipe.dropContents();
|
||||
dropBlockAsItem(world, i, j, k, new ItemStack(k1, 1, pipe.container.getItemMetadata()));
|
||||
if (k1 != null) {
|
||||
pipe.dropContents();
|
||||
for (ItemStack is: pipe.computeItemDrop()) {
|
||||
dropBlockAsItem(world, i, j, k, is);
|
||||
}
|
||||
dropBlockAsItem(world, i, j, k, new ItemStack(k1, 1, pipe.container.getItemMetadata()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -489,15 +489,6 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
|
|||
InvUtils.dropItems(container.getWorldObj(), stack, container.xCoord, container.yCoord, container.zCoord);
|
||||
}
|
||||
|
||||
public void onBlockRemoval() {
|
||||
|
||||
if (getWorld().getWorldInfo().getGameType() != GameType.CREATIVE) {
|
||||
for (ItemStack stack : computeItemDrop()) {
|
||||
dropItem(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> computeItemDrop() {
|
||||
ArrayList<ItemStack> result = new ArrayList<ItemStack>();
|
||||
|
||||
|
|
86
common/buildcraft/transport/PipeColoringRecipe.java
Normal file
86
common/buildcraft/transport/PipeColoringRecipe.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package buildcraft.transport;
|
||||
|
||||
import buildcraft.core.utils.ColorUtils;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PipeColoringRecipe implements IRecipe {
|
||||
|
||||
private ItemStack getResult(InventoryCrafting crafting) {
|
||||
ItemStack oneColorPipeStack = null;
|
||||
ItemStack pipeStack = null;
|
||||
|
||||
boolean hasDifferentColorPipes = false;
|
||||
boolean hasDifferentPipes = false;
|
||||
|
||||
boolean isBleach = false;
|
||||
ItemStack dye = null;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = crafting.getStackInSlot(i);
|
||||
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof ItemPipe) {
|
||||
if (pipeStack == null) {
|
||||
pipeStack = new ItemStack(stack.getItem(), 1, 0);
|
||||
oneColorPipeStack = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
|
||||
} else {
|
||||
if (stack.getItem() == pipeStack.getItem()) {
|
||||
pipeStack.stackSize++;
|
||||
if (oneColorPipeStack.getItemDamage() == oneColorPipeStack.getItemDamage()) {
|
||||
oneColorPipeStack.stackSize++;
|
||||
} else {
|
||||
hasDifferentColorPipes = true;
|
||||
}
|
||||
} else {
|
||||
hasDifferentColorPipes = true;
|
||||
hasDifferentPipes = true;
|
||||
}
|
||||
}
|
||||
} else if (stack.getItem() == Items.water_bucket) {
|
||||
isBleach = true;
|
||||
} else if (ColorUtils.isDye(stack)) {
|
||||
dye = stack;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBleach && dye != null) {
|
||||
return null;
|
||||
} else if ((isBleach || (dye != null && pipeStack.stackSize == 8)) && !hasDifferentPipes) {
|
||||
ItemStack result = pipeStack;
|
||||
if (dye != null) {
|
||||
result.setItemDamage(ColorUtils.getColorIDFromDye(dye) + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting crafting, World world) {
|
||||
return getResult(crafting) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting crafting) {
|
||||
return getResult(crafting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue