Re-added a single mode Wrench that can rotate blocks and break Refined Storage covers.
This commit is contained in:
@@ -23,4 +23,5 @@ public final class RSItems {
|
||||
public static final ItemCuttingTool CUTTING_TOOL = new ItemCuttingTool();
|
||||
public static final ItemCover COVER = new ItemCover();
|
||||
public static final ItemHollowCover HOLLOW_COVER = new ItemHollowCover();
|
||||
public static final ItemWrench WRENCH = new ItemWrench();
|
||||
}
|
||||
|
||||
@@ -63,13 +63,19 @@ public class CoverManager {
|
||||
return covers.containsKey(facing);
|
||||
}
|
||||
|
||||
public boolean setCover(EnumFacing facing, Cover cover) {
|
||||
if (isValidCover(cover.getStack()) && !hasCover(facing)) {
|
||||
if (facing == node.getDirection() && !(node instanceof NetworkNodeCable) && cover.getType() != CoverType.HOLLOW) {
|
||||
return false;
|
||||
public boolean setCover(EnumFacing facing, @Nullable Cover cover) {
|
||||
if (cover == null || (isValidCover(cover.getStack()) && !hasCover(facing))) {
|
||||
if (cover != null) {
|
||||
if (facing == node.getDirection() && !(node instanceof NetworkNodeCable) && cover.getType() != CoverType.HOLLOW) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
covers.put(facing, cover);
|
||||
if (cover == null) {
|
||||
covers.remove(facing);
|
||||
} else {
|
||||
covers.put(facing, cover);
|
||||
}
|
||||
|
||||
node.markDirty();
|
||||
|
||||
@@ -84,6 +90,8 @@ public class CoverManager {
|
||||
}
|
||||
|
||||
public void readFromNbt(NBTTagList list) {
|
||||
covers.clear();
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -21,7 +20,6 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -130,13 +128,7 @@ public abstract class BlockBase extends Block {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
|
||||
IItemHandler handler = ((TileBase) tile).getDrops();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||
if (!handler.getStackInSlot(i).isEmpty()) {
|
||||
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
WorldUtils.dropInventory(world, pos, ((TileBase) tile).getDrops());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
coverWest != null ? 2 : 0, coverDown != null ? 2 : 0, 0,
|
||||
coverEast != null ? 14 : 16, coverUp != null ? 14 : 16, 2
|
||||
)));
|
||||
)).setDirection(EnumFacing.NORTH));
|
||||
|
||||
if (coverNorth.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_NORTH);
|
||||
@@ -261,7 +261,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
14, coverDown != null ? 2 : 0, 0,
|
||||
16, coverUp != null ? 14 : 16, 16
|
||||
)));
|
||||
)).setDirection(EnumFacing.EAST));
|
||||
|
||||
if (coverEast.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_EAST);
|
||||
@@ -272,7 +272,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
coverEast != null ? 14 : 16, coverDown != null ? 2 : 0, 16,
|
||||
coverWest != null ? 2 : 0, coverUp != null ? 14 : 16, 14
|
||||
)));
|
||||
)).setDirection(EnumFacing.SOUTH));
|
||||
|
||||
if (coverSouth.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_SOUTH);
|
||||
@@ -283,7 +283,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
0, coverDown != null ? 2 : 0, 0,
|
||||
2, coverUp != null ? 14 : 16, 16
|
||||
)));
|
||||
)).setDirection(EnumFacing.WEST));
|
||||
|
||||
if (coverWest.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_WEST);
|
||||
@@ -294,7 +294,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
0, 14, 0,
|
||||
16, 16, 16
|
||||
)));
|
||||
)).setDirection(EnumFacing.UP));
|
||||
|
||||
if (coverUp.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_UP);
|
||||
@@ -305,7 +305,7 @@ public class BlockCable extends BlockNode {
|
||||
groups.add(new CollisionGroup().addItem(CollisionUtils.getBounds(
|
||||
0, 0, 0,
|
||||
16, 2, 16
|
||||
)));
|
||||
)).setDirection(EnumFacing.DOWN));
|
||||
|
||||
if (coverDown.getType() != CoverType.HOLLOW) {
|
||||
groups.add(ConstantsCable.HOLDER_DOWN);
|
||||
|
||||
@@ -150,6 +150,8 @@ public class ItemCover extends ItemBase {
|
||||
INetworkNode node = ((TileNode) tile).getNode();
|
||||
|
||||
if (node.getNetwork() != null && !node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, player)) {
|
||||
WorldUtils.sendNoPermissionMessage(player);
|
||||
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.raoulvdberge.refinedstorage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.ICoverable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockCable;
|
||||
import com.raoulvdberge.refinedstorage.item.info.ItemInfo;
|
||||
import com.raoulvdberge.refinedstorage.render.IModelRegistration;
|
||||
import com.raoulvdberge.refinedstorage.render.collision.AdvancedRayTraceResult;
|
||||
import com.raoulvdberge.refinedstorage.render.collision.AdvancedRayTracer;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileNode;
|
||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemWrench extends ItemBase {
|
||||
public ItemWrench() {
|
||||
super(new ItemInfo(RS.ID, "wrench"));
|
||||
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModels(IModelRegistration modelRegistration) {
|
||||
modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "inventory"));
|
||||
}
|
||||
|
||||
@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.FAIL;
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileNode && ((TileNode) tile).getNode().getNetwork() != null && !((TileNode) tile).getNode().getNetwork().getSecurityManager().hasPermission(Permission.BUILD, player)) {
|
||||
WorldUtils.sendNoPermissionMessage(player);
|
||||
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block instanceof BlockCable && tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable) {
|
||||
CoverManager manager = ((ICoverable) ((TileNode) tile).getNode()).getCoverManager();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
AdvancedRayTraceResult result = AdvancedRayTracer.rayTrace(
|
||||
pos,
|
||||
AdvancedRayTracer.getStart(player),
|
||||
AdvancedRayTracer.getEnd(player),
|
||||
((BlockCable) block).getCollisions(tile, block.getActualState(state, world, pos))
|
||||
);
|
||||
|
||||
if (result != null && result.getGroup().getDirection() != null) {
|
||||
EnumFacing facingSelected = result.getGroup().getDirection();
|
||||
|
||||
if (manager.hasCover(facingSelected)) {
|
||||
ItemStack cover = manager.getCover(facingSelected).getType().createStack();
|
||||
|
||||
ItemCover.setItem(cover, manager.getCover(facingSelected).getStack());
|
||||
|
||||
manager.setCover(facingSelected, null);
|
||||
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
|
||||
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), cover);
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
block.rotateBlock(world, pos, player.getHorizontalFacing().getOpposite());
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -242,6 +242,7 @@ public class ProxyCommon {
|
||||
registerItem(RSItems.SECURITY_CARD);
|
||||
registerItem(RSItems.COVER);
|
||||
registerItem(RSItems.HOLLOW_COVER);
|
||||
registerItem(RSItems.WRENCH);
|
||||
|
||||
IntegrationInventorySorter.register();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
public final class AdvancedRayTracer {
|
||||
@@ -23,6 +24,7 @@ public final class AdvancedRayTracer {
|
||||
return start.add(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AdvancedRayTraceResult<RayTraceResult> rayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<CollisionGroup> groups) {
|
||||
double minDistance = Double.POSITIVE_INFINITY;
|
||||
AdvancedRayTraceResult hit = null;
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.raoulvdberge.refinedstorage.render.collision;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CollisionGroup {
|
||||
private List<AxisAlignedBB> items = new ArrayList<>();
|
||||
private boolean canAccessGui;
|
||||
@Nullable
|
||||
private EnumFacing direction;
|
||||
|
||||
public CollisionGroup addItem(AxisAlignedBB item) {
|
||||
items.add(item);
|
||||
@@ -28,4 +32,15 @@ public class CollisionGroup {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CollisionGroup setDirection(EnumFacing direction) {
|
||||
this.direction = direction;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EnumFacing getDirection() {
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -53,4 +54,12 @@ public final class WorldUtils {
|
||||
public static void sendNoPermissionMessage(EntityPlayer player) {
|
||||
player.sendMessage(new TextComponentTranslation("misc.refinedstorage:security.no_permission").setStyle(new Style().setColor(TextFormatting.RED)));
|
||||
}
|
||||
|
||||
public static void dropInventory(World world, BlockPos pos, IItemHandler handler) {
|
||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||
if (!handler.getStackInSlot(i).isEmpty()) {
|
||||
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user