Constructor can now drop items in the world, fixes #449
This commit is contained in:
@@ -4,7 +4,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.items.SlotItemHandler;
|
import net.minecraftforge.items.SlotItemHandler;
|
||||||
import refinedstorage.container.slot.SlotSpecimen;
|
|
||||||
import refinedstorage.container.slot.SlotSpecimenType;
|
import refinedstorage.container.slot.SlotSpecimenType;
|
||||||
import refinedstorage.tile.TileConstructor;
|
import refinedstorage.tile.TileConstructor;
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ public class ContainerConstructor extends ContainerBase {
|
|||||||
addSlotToContainer(new SlotItemHandler(constructor.getUpgrades(), i, 187, 6 + (i * 18)));
|
addSlotToContainer(new SlotItemHandler(constructor.getUpgrades(), i, 187, 6 + (i * 18)));
|
||||||
}
|
}
|
||||||
|
|
||||||
addSlotToContainer(new SlotSpecimenType(constructor, 0, 80, 20, SlotSpecimen.SPECIMEN_BLOCK));
|
addSlotToContainer(new SlotSpecimenType(constructor, 0, 80, 20));
|
||||||
|
|
||||||
addPlayerInventory(8, 55);
|
addPlayerInventory(8, 55);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package refinedstorage.gui;
|
|||||||
import refinedstorage.api.util.IComparer;
|
import refinedstorage.api.util.IComparer;
|
||||||
import refinedstorage.container.ContainerConstructor;
|
import refinedstorage.container.ContainerConstructor;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
||||||
|
import refinedstorage.gui.sidebutton.SideButtonConstuctorDrop;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonType;
|
import refinedstorage.gui.sidebutton.SideButtonType;
|
||||||
import refinedstorage.tile.TileConstructor;
|
import refinedstorage.tile.TileConstructor;
|
||||||
@@ -20,6 +21,7 @@ public class GuiConstructor extends GuiBase {
|
|||||||
|
|
||||||
addSideButton(new SideButtonCompare(this, TileConstructor.COMPARE, IComparer.COMPARE_DAMAGE));
|
addSideButton(new SideButtonCompare(this, TileConstructor.COMPARE, IComparer.COMPARE_DAMAGE));
|
||||||
addSideButton(new SideButtonCompare(this, TileConstructor.COMPARE, IComparer.COMPARE_NBT));
|
addSideButton(new SideButtonCompare(this, TileConstructor.COMPARE, IComparer.COMPARE_NBT));
|
||||||
|
addSideButton(new SideButtonConstuctorDrop(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
27
src/main/java/refinedstorage/gui/sidebutton/SideButtonConstuctorDrop.java
Executable file
27
src/main/java/refinedstorage/gui/sidebutton/SideButtonConstuctorDrop.java
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
package refinedstorage.gui.sidebutton;
|
||||||
|
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import refinedstorage.gui.GuiBase;
|
||||||
|
import refinedstorage.tile.TileConstructor;
|
||||||
|
import refinedstorage.tile.data.TileDataManager;
|
||||||
|
|
||||||
|
public class SideButtonConstuctorDrop extends SideButton {
|
||||||
|
public SideButtonConstuctorDrop(GuiBase gui) {
|
||||||
|
super(gui);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawButtonIcon(int x, int y) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTooltip() {
|
||||||
|
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:constructor.drop") + TextFormatting.RESET + "\n" + gui.t(TileConstructor.DROP.getValue() ? "gui.yes" : "gui.no");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed() {
|
||||||
|
TileDataManager.setParameter(TileConstructor.DROP, !TileConstructor.DROP.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,12 @@ import mcmultipart.microblock.IMicroblock;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||||
|
import net.minecraft.dispenser.PositionImpl;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.datasync.DataSerializers;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -25,14 +28,30 @@ import refinedstorage.inventory.ItemHandlerUpgrade;
|
|||||||
import refinedstorage.item.ItemUpgrade;
|
import refinedstorage.item.ItemUpgrade;
|
||||||
import refinedstorage.tile.config.IComparable;
|
import refinedstorage.tile.config.IComparable;
|
||||||
import refinedstorage.tile.config.IType;
|
import refinedstorage.tile.config.IType;
|
||||||
|
import refinedstorage.tile.data.ITileDataConsumer;
|
||||||
|
import refinedstorage.tile.data.ITileDataProducer;
|
||||||
import refinedstorage.tile.data.TileDataParameter;
|
import refinedstorage.tile.data.TileDataParameter;
|
||||||
|
|
||||||
public class TileConstructor extends TileMultipartNode implements IComparable, IType {
|
public class TileConstructor extends TileMultipartNode implements IComparable, IType {
|
||||||
public static final TileDataParameter<Integer> COMPARE = IComparable.createParameter();
|
public static final TileDataParameter<Integer> COMPARE = IComparable.createParameter();
|
||||||
public static final TileDataParameter<Integer> TYPE = IType.createParameter();
|
public static final TileDataParameter<Integer> TYPE = IType.createParameter();
|
||||||
|
public static final TileDataParameter<Boolean> DROP = new TileDataParameter<>(DataSerializers.BOOLEAN, false, new ITileDataProducer<Boolean, TileConstructor>() {
|
||||||
|
@Override
|
||||||
|
public Boolean getValue(TileConstructor tile) {
|
||||||
|
return tile.drop;
|
||||||
|
}
|
||||||
|
}, new ITileDataConsumer<Boolean, TileConstructor>() {
|
||||||
|
@Override
|
||||||
|
public void setValue(TileConstructor tile, Boolean value) {
|
||||||
|
tile.drop = value;
|
||||||
|
|
||||||
|
tile.markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private static final String NBT_COMPARE = "Compare";
|
private static final String NBT_COMPARE = "Compare";
|
||||||
private static final String NBT_TYPE = "Type";
|
private static final String NBT_TYPE = "Type";
|
||||||
|
private static final String NBT_DROP = "Drop";
|
||||||
|
|
||||||
private static final int BASE_SPEED = 20;
|
private static final int BASE_SPEED = 20;
|
||||||
|
|
||||||
@@ -41,7 +60,8 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
protected void onContentsChanged(int slot) {
|
protected void onContentsChanged(int slot) {
|
||||||
super.onContentsChanged(slot);
|
super.onContentsChanged(slot);
|
||||||
|
|
||||||
block = SlotSpecimen.getBlockState(worldObj, pos.offset(getDirection()), getStackInSlot(0));
|
item = getStackInSlot(slot) == null ? null : getStackInSlot(slot).copy();
|
||||||
|
block = SlotSpecimen.getBlockState(worldObj, pos.offset(getDirection()), getStackInSlot(slot));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,12 +71,15 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
|
|
||||||
private int compare = IComparer.COMPARE_NBT | IComparer.COMPARE_DAMAGE;
|
private int compare = IComparer.COMPARE_NBT | IComparer.COMPARE_DAMAGE;
|
||||||
private int type = IType.ITEMS;
|
private int type = IType.ITEMS;
|
||||||
|
private boolean drop = false;
|
||||||
|
|
||||||
private IBlockState block;
|
private IBlockState block;
|
||||||
|
private ItemStack item;
|
||||||
|
|
||||||
public TileConstructor() {
|
public TileConstructor() {
|
||||||
dataManager.addWatchedParameter(COMPARE);
|
dataManager.addWatchedParameter(COMPARE);
|
||||||
dataManager.addWatchedParameter(TYPE);
|
dataManager.addWatchedParameter(TYPE);
|
||||||
|
dataManager.addWatchedParameter(DROP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,26 +95,15 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
@Override
|
@Override
|
||||||
public void updateNode() {
|
public void updateNode() {
|
||||||
if (ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
|
if (ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
|
||||||
if (type == IType.ITEMS && block != null) {
|
if (type == IType.ITEMS) {
|
||||||
BlockPos front = pos.offset(getDirection());
|
if (block != null) {
|
||||||
|
if (drop && item != null) {
|
||||||
if (worldObj.isAirBlock(front) && block.getBlock().canPlaceBlockAt(worldObj, front)) {
|
dropItem();
|
||||||
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare);
|
} else {
|
||||||
|
placeBlock();
|
||||||
if (took != null) {
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
IBlockState state = block.getBlock().getStateFromMeta(took.getMetadata());
|
|
||||||
|
|
||||||
worldObj.setBlockState(front, state, 1 | 2);
|
|
||||||
|
|
||||||
// From ItemBlock#onItemUse
|
|
||||||
SoundType blockSound = block.getBlock().getSoundType(state, worldObj, pos, null);
|
|
||||||
worldObj.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F);
|
|
||||||
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
|
||||||
ItemStack craft = itemFilters.getStackInSlot(0);
|
|
||||||
|
|
||||||
network.scheduleCraftingTaskIfUnscheduled(craft, 1, compare);
|
|
||||||
}
|
}
|
||||||
|
} else if (item != null) {
|
||||||
|
dropItem();
|
||||||
}
|
}
|
||||||
} else if (type == IType.FLUIDS) {
|
} else if (type == IType.FLUIDS) {
|
||||||
FluidStack stack = fluidFilters.getFluidStackInSlot(0);
|
FluidStack stack = fluidFilters.getFluidStackInSlot(0);
|
||||||
@@ -121,6 +133,42 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void placeBlock() {
|
||||||
|
BlockPos front = pos.offset(getDirection());
|
||||||
|
|
||||||
|
if (worldObj.isAirBlock(front) && block.getBlock().canPlaceBlockAt(worldObj, front)) {
|
||||||
|
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), 1, compare);
|
||||||
|
|
||||||
|
if (took != null) {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
IBlockState state = block.getBlock().getStateFromMeta(took.getMetadata());
|
||||||
|
|
||||||
|
worldObj.setBlockState(front, state, 1 | 2);
|
||||||
|
|
||||||
|
// From ItemBlock#onItemUse
|
||||||
|
SoundType blockSound = block.getBlock().getSoundType(state, worldObj, pos, null);
|
||||||
|
worldObj.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F);
|
||||||
|
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
||||||
|
ItemStack craft = itemFilters.getStackInSlot(0);
|
||||||
|
|
||||||
|
network.scheduleCraftingTaskIfUnscheduled(craft, 1, compare);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropItem() {
|
||||||
|
ItemStack took = network.extractItem(item, 1);
|
||||||
|
|
||||||
|
if (took != null) {
|
||||||
|
// From BlockDispenser#getDispensePosition
|
||||||
|
double x = (double) pos.getX() + 0.5D + 0.8D * (double) getDirection().getFrontOffsetX();
|
||||||
|
double y = (double) pos.getY() + (getDirection() == EnumFacing.DOWN ? 0.45D : 0.5D) + 0.8D * (double) getDirection().getFrontOffsetY();
|
||||||
|
double z = (double) pos.getZ() + 0.5D + 0.8D * (double) getDirection().getFrontOffsetZ();
|
||||||
|
|
||||||
|
BehaviorDefaultDispenseItem.doDispense(worldObj, took, 6, getDirection(), new PositionImpl(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare() {
|
||||||
return compare;
|
return compare;
|
||||||
@@ -145,6 +193,10 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
type = tag.getInteger(NBT_TYPE);
|
type = tag.getInteger(NBT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag.hasKey(NBT_DROP)) {
|
||||||
|
drop = tag.getBoolean(NBT_DROP);
|
||||||
|
}
|
||||||
|
|
||||||
RSUtils.readItems(itemFilters, 0, tag);
|
RSUtils.readItems(itemFilters, 0, tag);
|
||||||
RSUtils.readItems(upgrades, 1, tag);
|
RSUtils.readItems(upgrades, 1, tag);
|
||||||
RSUtils.readItems(fluidFilters, 2, tag);
|
RSUtils.readItems(fluidFilters, 2, tag);
|
||||||
@@ -156,6 +208,7 @@ public class TileConstructor extends TileMultipartNode implements IComparable, I
|
|||||||
|
|
||||||
tag.setInteger(NBT_COMPARE, compare);
|
tag.setInteger(NBT_COMPARE, compare);
|
||||||
tag.setInteger(NBT_TYPE, type);
|
tag.setInteger(NBT_TYPE, type);
|
||||||
|
tag.setBoolean(NBT_DROP, drop);
|
||||||
|
|
||||||
RSUtils.writeItems(itemFilters, 0, tag);
|
RSUtils.writeItems(itemFilters, 0, tag);
|
||||||
RSUtils.writeItems(upgrades, 1, tag);
|
RSUtils.writeItems(upgrades, 1, tag);
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ sidebutton.refinedstorage:void_excess.items=Void excess items
|
|||||||
sidebutton.refinedstorage:void_excess.fluids=Void excess fluids
|
sidebutton.refinedstorage:void_excess.fluids=Void excess fluids
|
||||||
sidebutton.refinedstorage:void_excess.items_fluids=Void excess items and fluids
|
sidebutton.refinedstorage:void_excess.items_fluids=Void excess items and fluids
|
||||||
|
|
||||||
|
sidebutton.refinedstorage:constructor.drop=Drop blocks as item
|
||||||
|
|
||||||
block.refinedstorage:controller.0.name=Controller
|
block.refinedstorage:controller.0.name=Controller
|
||||||
block.refinedstorage:controller.1.name=Creative Controller
|
block.refinedstorage:controller.1.name=Creative Controller
|
||||||
block.refinedstorage:cable.name=Cable
|
block.refinedstorage:cable.name=Cable
|
||||||
|
|||||||
Reference in New Issue
Block a user