Added Wrench dismantling mode. Fixes #795
This commit is contained in:
@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.util;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.block.BlockNode;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
@@ -179,6 +180,9 @@ public class Comparer implements IComparer {
|
|||||||
stack.getTagCompound().removeTag("sjData");
|
stack.getTagCompound().removeTag("sjData");
|
||||||
stack.getTagCompound().removeTag("PackOn");
|
stack.getTagCompound().removeTag("PackOn");
|
||||||
break;
|
break;
|
||||||
|
case "refinedstorage":
|
||||||
|
stack.getTagCompound().removeTag(BlockNode.NBT_REFINED_STORAGE_DATA);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import net.minecraft.block.state.BlockStateContainer;
|
|||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public abstract class BlockNode extends BlockBase {
|
public abstract class BlockNode extends BlockBase {
|
||||||
|
public static final String NBT_REFINED_STORAGE_DATA = "RefinedStorageData";
|
||||||
|
|
||||||
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
|
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
|
||||||
|
|
||||||
public BlockNode(String name) {
|
public BlockNode(String name) {
|
||||||
@@ -28,6 +31,15 @@ public abstract class BlockNode extends BlockBase {
|
|||||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||||
|
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
|
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_REFINED_STORAGE_DATA)) {
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileNode) {
|
||||||
|
((TileNode) tile).getNode().readConfiguration(stack.getTagCompound().getCompoundTag(NBT_REFINED_STORAGE_DATA));
|
||||||
|
((TileNode) tile).getNode().markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
API.instance().discoverNode(world, pos);
|
API.instance().discoverNode(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
|
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
|
||||||
|
import com.raoulvdberge.refinedstorage.block.BlockNode;
|
||||||
|
import com.raoulvdberge.refinedstorage.tile.TileNode;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@@ -22,7 +26,8 @@ import java.util.List;
|
|||||||
public class ItemWrench extends ItemBase {
|
public class ItemWrench extends ItemBase {
|
||||||
private enum WrenchMode {
|
private enum WrenchMode {
|
||||||
ROTATION(0),
|
ROTATION(0),
|
||||||
CONFIGURATION(1);
|
CONFIGURATION(1),
|
||||||
|
DISMANTLING(2);
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
@@ -31,7 +36,7 @@ public class ItemWrench extends ItemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WrenchMode cycle() {
|
public WrenchMode cycle() {
|
||||||
return this == ROTATION ? CONFIGURATION : ROTATION;
|
return this == ROTATION ? CONFIGURATION : (this == CONFIGURATION ? DISMANTLING : ROTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||||
@@ -115,6 +120,28 @@ public class ItemWrench extends ItemBase {
|
|||||||
|
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
} else if (mode == WrenchMode.DISMANTLING) {
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
IBlockState state = world.getBlockState(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileNode) {
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
|
||||||
|
((TileNode) tile).writeConfiguration(data);
|
||||||
|
|
||||||
|
ItemStack tileStack = new ItemStack(
|
||||||
|
state.getBlock(),
|
||||||
|
1,
|
||||||
|
state.getBlock().getMetaFromState(state)
|
||||||
|
);
|
||||||
|
|
||||||
|
tileStack.setTagCompound(new NBTTagCompound());
|
||||||
|
tileStack.getTagCompound().setTag(BlockNode.NBT_REFINED_STORAGE_DATA, data);
|
||||||
|
|
||||||
|
world.setBlockToAir(pos);
|
||||||
|
|
||||||
|
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), tileStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EnumActionResult.PASS;
|
return EnumActionResult.PASS;
|
||||||
|
|||||||
@@ -271,5 +271,6 @@ item.refinedstorage:wrench.read=Configuration read.
|
|||||||
item.refinedstorage:wrench.mode=Mode: %s
|
item.refinedstorage:wrench.mode=Mode: %s
|
||||||
item.refinedstorage:wrench.mode.0=Rotation
|
item.refinedstorage:wrench.mode.0=Rotation
|
||||||
item.refinedstorage:wrench.mode.1=Configuration
|
item.refinedstorage:wrench.mode.1=Configuration
|
||||||
|
item.refinedstorage:wrench.mode.2=Dismantling
|
||||||
item.refinedstorage:security_card.name=Security Card
|
item.refinedstorage:security_card.name=Security Card
|
||||||
item.refinedstorage:security_card.owner=Bound to: %s
|
item.refinedstorage:security_card.owner=Bound to: %s
|
||||||
Reference in New Issue
Block a user