Implement wrench modes
This commit is contained in:
@@ -89,7 +89,7 @@ public abstract class BlockBase extends Block {
|
||||
if (!world.isRemote && getPlacementType() != null) {
|
||||
TileBase tile = (TileBase) world.getTileEntity(pos);
|
||||
|
||||
tile.setDirection(getPlacementType().getNext(tile.getDirection()));
|
||||
tile.setDirection(getPlacementType().cycle(tile.getDirection()));
|
||||
|
||||
tile.updateBlock();
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ public class BlockCable extends BlockCoverable {
|
||||
if (!world.isRemote && getPlacementType() != null) {
|
||||
TileBase tile = (TileBase) world.getTileEntity(pos);
|
||||
|
||||
tile.setDirection(getPlacementType().getNext(tile.getDirection()));
|
||||
tile.setDirection(getPlacementType().cycle(tile.getDirection()));
|
||||
|
||||
tile.updateBlock();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum EnumPlacementType {
|
||||
}
|
||||
}
|
||||
|
||||
public EnumFacing getNext(EnumFacing previous) {
|
||||
public EnumFacing cycle(EnumFacing previous) {
|
||||
switch (this) {
|
||||
case ANY:
|
||||
case ANY_FACE_PLAYER:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -10,10 +12,51 @@ import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
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 java.util.List;
|
||||
|
||||
public class ItemWrench extends ItemBase {
|
||||
private enum WrenchMode {
|
||||
ROTATION(0),
|
||||
CONFIGURATION(1);
|
||||
|
||||
private final int id;
|
||||
|
||||
WrenchMode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public WrenchMode cycle() {
|
||||
return this == ROTATION ? CONFIGURATION : 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() {
|
||||
@@ -29,41 +72,50 @@ public class ItemWrench extends ItemBase {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
WrenchMode mode = WrenchMode.readFromNBT(stack.getTagCompound());
|
||||
|
||||
if (tile instanceof IWrenchable) {
|
||||
IWrenchable wrenchable = (IWrenchable) tile;
|
||||
if (mode == WrenchMode.ROTATION) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
|
||||
boolean canWrite = false;
|
||||
block.rotateBlock(world, pos, player.getHorizontalFacing().getOpposite());
|
||||
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_WRENCHED_TILE)) {
|
||||
String wrenchedTile = stack.getTagCompound().getString(NBT_WRENCHED_TILE);
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else if (mode == WrenchMode.CONFIGURATION) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (wrenchable.getClass().getName().equals(wrenchedTile)) {
|
||||
wrenchable.readConfiguration(stack.getTagCompound());
|
||||
tile.markDirty();
|
||||
if (tile instanceof IWrenchable) {
|
||||
IWrenchable wrenchable = (IWrenchable) tile;
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation("item.refinedstorage:wrench.read"));
|
||||
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.addChatComponentMessage(new TextComponentTranslation("item.refinedstorage:wrench.read"));
|
||||
} else {
|
||||
canWrite = true;
|
||||
}
|
||||
} 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.addChatComponentMessage(new TextComponentTranslation("item.refinedstorage:wrench.saved"));
|
||||
}
|
||||
|
||||
stack.damageItem(1, player);
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (canWrite) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setString(NBT_WRENCHED_TILE, wrenchable.getClass().getName());
|
||||
|
||||
stack.setTagCompound(wrenchable.writeConfiguration(tag));
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation("item.refinedstorage:wrench.saved"));
|
||||
}
|
||||
|
||||
stack.damageItem(1, player);
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
@@ -72,11 +124,29 @@ public class ItemWrench extends ItemBase {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote && !player.isSneaking()) {
|
||||
WrenchMode mode = WrenchMode.readFromNBT(stack.getTagCompound());
|
||||
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation("item.refinedstorage:wrench.cleared"));
|
||||
WrenchMode next = mode.cycle();
|
||||
|
||||
next.writeToNBT(stack.getTagCompound());
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation(
|
||||
"item.refinedstorage:wrench.mode",
|
||||
new TextComponentTranslation("item.refinedstorage:wrench.mode." + next.id).setStyle(new Style().setColor(TextFormatting.YELLOW))
|
||||
));
|
||||
}
|
||||
|
||||
return super.onItemRightClick(stack, world, player, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
super.addInformation(stack, player, tooltip, advanced);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ public class ProxyClient extends ProxyCommon {
|
||||
ModelLoader.setCustomModelResourceLocation(RSItems.STORAGE_HOUSING, 0, new ModelResourceLocation("refinedstorage:storage_housing", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(RSItems.GRID_FILTER, 0, new ModelResourceLocation("refinedstorage:grid_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.UPGRADE, 0, new ModelResourceLocation("refinedstorage:upgrade", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(RSItems.UPGRADE, ItemUpgrade.TYPE_RANGE, new ModelResourceLocation("refinedstorage:range_upgrade", "inventory"));
|
||||
|
||||
@@ -99,7 +99,6 @@ public class ProxyCommon {
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ContainerListener());
|
||||
MinecraftForge.EVENT_BUS.register(RSItems.WRENCH);
|
||||
|
||||
registerTile(TileController.class, "controller");
|
||||
registerTile(TileGrid.class, "grid");
|
||||
|
||||
@@ -228,4 +228,6 @@ item.refinedstorage:network_card.name=Network Card
|
||||
item.refinedstorage:wrench.name=Wrench
|
||||
item.refinedstorage:wrench.saved=Configuration written.
|
||||
item.refinedstorage:wrench.read=Configuration read.
|
||||
item.refinedstorage:wrench.cleared=Configuration cleared.
|
||||
item.refinedstorage:wrench.mode=Mode: %s
|
||||
item.refinedstorage:wrench.mode.0=Rotation
|
||||
item.refinedstorage:wrench.mode.1=Configuration
|
||||
6
src/main/resources/assets/refinedstorage/models/item/wrench.json
Executable file
6
src/main/resources/assets/refinedstorage/models/item/wrench.json
Executable file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "refinedstorage:items/wrench"
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/refinedstorage/textures/items/wrench.png
Executable file
BIN
src/main/resources/assets/refinedstorage/textures/items/wrench.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 372 B |
Reference in New Issue
Block a user