Remove the Wrench

This commit is contained in:
raoulvdberge
2018-05-26 15:58:07 +02:00
parent 2eeba970a3
commit 3d8cdfcc0c
21 changed files with 10 additions and 345 deletions

View File

@@ -19,6 +19,5 @@ public final class RSItems {
public static final ItemNetworkCard NETWORK_CARD = new ItemNetworkCard();
public static final ItemFluidStorageDisk FLUID_STORAGE_DISK = new ItemFluidStorageDisk();
public static final ItemFluidStoragePart FLUID_STORAGE_PART = new ItemFluidStoragePart();
public static final ItemWrench WRENCH = new ItemWrench();
public static final ItemSecurityCard SECURITY_CARD = new ItemSecurityCard();
}

View File

@@ -1,23 +0,0 @@
package com.raoulvdberge.refinedstorage.api.util;
import net.minecraft.nbt.NBTTagCompound;
/**
* Implement this on a tile that is wrenchable.
*/
public interface IWrenchable {
/**
* Writes the configuration of this tile to the wrench.
*
* @param tag the tag to write to
* @return the written tag
*/
NBTTagCompound writeConfiguration(NBTTagCompound tag);
/**
* Reads the configuration of this tile from the wrench.
*
* @param tag the tag to read
*/
void readConfiguration(NBTTagCompound tag);
}

View File

@@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.network.INetworkNodeVisitor;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.TileBase;
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
@@ -22,7 +21,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID;
public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor, IWrenchable {
public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor {
private static final String NBT_OWNER = "Owner";
@Nullable
@@ -149,7 +148,6 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor,
return tag;
}
@Override
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
redstoneMode.write(tag);
@@ -164,7 +162,6 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor,
readConfiguration(tag);
}
@Override
public void readConfiguration(NBTTagCompound tag) {
redstoneMode = RedstoneMode.read(tag);
}

View File

@@ -1,7 +1,6 @@
package com.raoulvdberge.refinedstorage.apiimpl.util;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.block.BlockNode;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
@@ -176,9 +175,6 @@ public class Comparer implements IComparer {
stack.getTagCompound().removeTag("sjData");
stack.getTagCompound().removeTag("PackOn");
break;
case "refinedstorage":
stack.getTagCompound().removeTag(BlockNode.NBT_REFINED_STORAGE_DATA);
break;
case "immersiveengineering":
stack.getTagCompound().removeTag("hammerDmg");
stack.getTagCompound().removeTag("cutterDmg");

View File

@@ -16,8 +16,6 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockNode extends BlockBase {
public static final String NBT_REFINED_STORAGE_DATA = "RefinedStorageData";
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
public BlockNode(String name) {
@@ -36,15 +34,8 @@ public abstract class BlockNode extends BlockBase {
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_REFINED_STORAGE_DATA)) {
((TileNode) tile).getNode().readConfiguration(stack.getTagCompound().getCompoundTag(NBT_REFINED_STORAGE_DATA));
((TileNode) tile).getNode().markDirty();
}
if (placer instanceof EntityPlayer) {
((TileNode) tile).getNode().setOwner(((EntityPlayer) placer).getGameProfile().getId());
}
if (tile instanceof TileNode && placer instanceof EntityPlayer) {
((TileNode) tile).getNode().setOwner(((EntityPlayer) placer).getGameProfile().getId());
}
API.instance().discoverNode(world, pos);

View File

@@ -1,189 +0,0 @@
package com.raoulvdberge.refinedstorage.item;
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.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.List;
public class ItemWrench extends ItemBase {
private enum WrenchMode {
ROTATION(0),
CONFIGURATION(1),
DISMANTLING(2);
private final int id;
WrenchMode(int id) {
this.id = id;
}
public WrenchMode cycle() {
return this == ROTATION ? CONFIGURATION : (this == CONFIGURATION ? DISMANTLING : ROTATION);
}
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
tag.setInteger(NBT_WRENCH_MODE, id);
return tag;
}
public static WrenchMode readFromNBT(NBTTagCompound tag) {
if (tag != null && tag.hasKey(NBT_WRENCH_MODE)) {
int id = tag.getInteger(NBT_WRENCH_MODE);
for (WrenchMode mode : values()) {
if (mode.id == id) {
return mode;
}
}
}
return ROTATION;
}
}
private static final String NBT_WRENCH_MODE = "WrenchMode";
private static final String NBT_WRENCHED_DATA = "WrenchedData";
private static final String NBT_WRENCHED_TILE = "WrenchedTile";
public ItemWrench() {
super("wrench");
setMaxStackSize(1);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!player.isSneaking()) {
return EnumActionResult.PASS;
}
if (world.isRemote) {
return EnumActionResult.SUCCESS;
}
ItemStack stack = player.getHeldItem(hand);
WrenchMode mode = WrenchMode.readFromNBT(stack.getTagCompound());
if (mode == WrenchMode.ROTATION) {
Block block = world.getBlockState(pos).getBlock();
block.rotateBlock(world, pos, player.getHorizontalFacing().getOpposite());
return EnumActionResult.SUCCESS;
} else if (mode == WrenchMode.CONFIGURATION) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IWrenchable) {
IWrenchable wrenchable = (IWrenchable) tile;
boolean canWrite = false;
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_WRENCHED_DATA) && stack.getTagCompound().hasKey(NBT_WRENCHED_TILE)) {
NBTTagCompound wrenchedData = stack.getTagCompound().getCompoundTag(NBT_WRENCHED_DATA);
String wrenchedTile = stack.getTagCompound().getString(NBT_WRENCHED_TILE);
if (wrenchable.getClass().getName().equals(wrenchedTile)) {
wrenchable.readConfiguration(wrenchedData);
tile.markDirty();
player.sendMessage(new TextComponentTranslation("item.refinedstorage:wrench.read"));
} else {
canWrite = true;
}
} else {
canWrite = true;
}
if (canWrite) {
stack.getTagCompound().setString(NBT_WRENCHED_TILE, wrenchable.getClass().getName());
stack.getTagCompound().setTag(NBT_WRENCHED_DATA, wrenchable.writeConfiguration(new NBTTagCompound()));
player.sendMessage(new TextComponentTranslation("item.refinedstorage:wrench.saved"));
}
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);
NonNullList<ItemStack> drops = NonNullList.create();
state.getBlock().getDrops(drops, world, pos, state, 0);
ItemStack tileStack = drops.get(0);
if (!tileStack.hasTagCompound()) {
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;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote && !player.isSneaking()) {
ItemStack stack = player.getHeldItem(hand);
WrenchMode mode = WrenchMode.readFromNBT(stack.getTagCompound());
if (stack.hasTagCompound()) {
stack.getTagCompound().removeTag(NBT_WRENCHED_TILE);
stack.getTagCompound().removeTag(NBT_WRENCHED_DATA);
} else {
stack.setTagCompound(new NBTTagCompound());
}
WrenchMode next = mode.cycle();
next.writeToNBT(stack.getTagCompound());
player.sendMessage(new TextComponentTranslation(
"item.refinedstorage:wrench.mode",
new TextComponentTranslation("item.refinedstorage:wrench.mode." + next.id).setStyle(new Style().setColor(TextFormatting.YELLOW))
));
}
return super.onItemRightClick(world, player, hand);
}
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
WrenchMode mode = WrenchMode.readFromNBT(stack.getTagCompound());
tooltip.add(I18n.format("item.refinedstorage:wrench.mode", TextFormatting.YELLOW + I18n.format("item.refinedstorage:wrench.mode." + mode.id) + TextFormatting.RESET));
}
}

View File

@@ -181,7 +181,6 @@ public class ProxyClient extends ProxyCommon {
ModelLoader.setCustomModelResourceLocation(RSItems.STORAGE_HOUSING, 0, new ModelResourceLocation("refinedstorage:storage_housing", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.FILTER, 0, new ModelResourceLocation("refinedstorage:filter", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.NETWORK_CARD, 0, new ModelResourceLocation("refinedstorage:network_card", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.WRENCH, 0, new ModelResourceLocation("refinedstorage:wrench", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.SECURITY_CARD, 0, new ModelResourceLocation("refinedstorage:security_card", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.UPGRADE, 0, new ModelResourceLocation("refinedstorage:upgrade", "inventory"));

View File

@@ -221,7 +221,6 @@ public class ProxyCommon {
registerItem(RSItems.UPGRADE);
registerItem(RSItems.FILTER);
registerItem(RSItems.NETWORK_CARD);
registerItem(RSItems.WRENCH);
registerItem(RSItems.SECURITY_CARD);
IntegrationInventorySorter.register();
@@ -282,28 +281,6 @@ public class ProxyCommon {
itemsToRegister.forEach(e.getRegistry()::register);
}
@SubscribeEvent
public void fixItemMappings(RegistryEvent.MissingMappings<Item> e) {
for (RegistryEvent.MissingMappings.Mapping<Item> missing : e.getMappings()) {
if (missing.key.getResourceDomain().equals(RS.ID)) {
if (missing.key.getResourcePath().equals("grid_filter")) {
missing.remap(RSItems.FILTER);
} else if (missing.key.getResourcePath().equals("processing_pattern_encoder")) {
missing.ignore();
}
}
}
}
@SubscribeEvent
public void fixBlockMappings(RegistryEvent.MissingMappings<Block> e) {
for (RegistryEvent.MissingMappings.Mapping<Block> missing : e.getMappings()) {
if (missing.key.getResourceDomain().equals(RS.ID) && missing.key.getResourcePath().equals("processing_pattern_encoder")) {
missing.ignore();
}
}
}
@SubscribeEvent
public void onHarvestCheck(PlayerEvent.HarvestCheck e) {
if (e.getTargetBlock().getBlock() instanceof BlockBase) {

View File

@@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
@@ -20,7 +19,7 @@ import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class TileNode<N extends NetworkNode> extends TileBase implements INetworkNodeProxy<N>, IRedstoneConfigurable, IWrenchable {
public abstract class TileNode<N extends NetworkNode> extends TileBase implements INetworkNodeProxy<N>, IRedstoneConfigurable {
public static final TileDataParameter<Integer, TileNode> REDSTONE_MODE = RedstoneMode.createParameter();
protected static final String NBT_ACTIVE = "Active";
@@ -41,11 +40,15 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
getNode().setRedstoneMode(mode);
}
@Override
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
return getNode().writeConfiguration(tag);
}
public void readConfiguration(NBTTagCompound tag) {
getNode().readConfiguration(tag);
getNode().markDirty();
}
@Override
public void setDirection(EnumFacing direction) {
super.setDirection(direction);
@@ -53,12 +56,6 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
getNode().resetDirection();
}
@Override
public void readConfiguration(NBTTagCompound tag) {
getNode().readConfiguration(tag);
getNode().markDirty();
}
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
super.writeUpdate(tag);