Add block rotation and small fixes

This commit is contained in:
raoulvdberge
2019-10-03 22:45:03 +02:00
parent 6845a45f7f
commit 06743af824
13 changed files with 87 additions and 226 deletions

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Rotation;
public abstract class BaseBlock extends Block {
public BaseBlock(Properties properties) {
@@ -14,6 +15,16 @@ public abstract class BaseBlock extends Block {
return BlockDirection.NONE;
}
@Override
public BlockState rotate(BlockState state, Rotation rot) {
BlockDirection dir = getDirection();
if (dir != BlockDirection.NONE) {
return state.with(dir.getProperty(), dir.cycle(state.get(dir.getProperty())));
}
return super.rotate(state, rot);
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);

View File

@@ -64,56 +64,6 @@ public abstract class BlockBase extends Block {
public Item createItem() {
return new ItemBlockBase(this);
}
/* TODO
@Override
public boolean rotateBlock(World world, BlockPos pos, Direction axis) {
if (!world.isRemote && getDirection() != null) {
TileBase tile = (TileBase) world.getTileEntity(pos);
Direction newDirection = getDirection().cycle(tile.getDirection());
tile.setDirection(newDirection);
WorldUtils.updateBlock(world, pos);
return true;
}
return false;
} */
/* TODO
@Override
public void breakBlock(World world, BlockPos pos, BlockState state) {
dropContents(world, pos);
removeTile(world, pos, state);
}
void removeTile(World world, BlockPos pos, BlockState state) {
if (hasTileEntity(state)) {
world.removeTileEntity(pos);
}
}
void dropContents(World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
WorldUtils.dropInventory(world, pos, ((TileBase) tile).getDrops());
}
}
@Override
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest) {
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest);
}
@Override
public void harvestBlock(World world, PlayerEntity player, BlockPos pos, BlockState state, TileEntity tile, ItemStack stack) {
super.harvestBlock(world, player, pos, state, tile, stack);
world.setBlockToAir(pos);
}*/
@Override
public final boolean hasTileEntity(BlockState state) {

View File

@@ -1,78 +1,11 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.block.info.IBlockInfo;
import net.minecraft.state.BooleanProperty;
public abstract class BlockNode extends BlockNodeProxy {
public static final BooleanProperty CONNECTED = BooleanProperty.create("connected");
public abstract class BlockNode extends BlockBase {
public BlockNode(IBlockInfo info) {
super(info);
}
/* TODO - Remove this class.
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, EntityLivingBase placer, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, placer, stack);
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode && placer instanceof PlayerEntity) {
((TileNode) tile).getNode().setOwner(((PlayerEntity) placer).getGameProfile().getId());
}
API.instance().discoverNode(world, pos);
}
}
@Override
public void breakBlock(World world, BlockPos pos, BlockState state) {
INetworkNodeManager manager = API.instance().getNetworkNodeManager(world);
INetworkNode node = manager.getNode(pos);
dropContents(world, pos);
removeTile(world, pos, state);
manager.removeNode(pos);
manager.markForSaving();
if (node != null && node.getNetwork() != null) {
node.getNetwork().getNodeGraph().invalidate(Action.PERFORM, node.getNetwork().world(), node.getNetwork().getPosition());
}
}
@Override
protected BlockStateContainer.Builder createBlockStateBuilder() {
BlockStateContainer.Builder builder = super.createBlockStateBuilder();
if (hasConnectedState()) {
builder.add(CONNECTED);
}
return builder;
}
@Override
protected BlockStateContainer createBlockState() {
return createBlockStateBuilder().build();
}
@Override
public BlockState getActualState(BlockState state, IBlockAccess world, BlockPos pos) {
state = super.getActualState(state, world, pos);
if (hasConnectedState()) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode) {
return state.withProperty(CONNECTED, ((TileNode) tile).getNode().isActive());
}
}
return state;
}*/
public boolean hasConnectedState() {
return false;

View File

@@ -1,85 +0,0 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.block.info.IBlockInfo;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
public abstract class BlockNodeProxy extends BlockBase {
public BlockNodeProxy(IBlockInfo info) {
this(Block.Properties.create(Material.ROCK));
}
public BlockNodeProxy(Properties p_i48440_1_) {
super(p_i48440_1_);
}
/* TODO - Remove this class...
@Override
public boolean canEntityDestroy(BlockState state, IBlockAccess world, BlockPos pos, Entity entity) {
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, null)) {
INetworkNode node = tile.getCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, null).getNode();
if (node.getNetwork() != null) {
return entity instanceof PlayerEntity && node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, (PlayerEntity) entity);
}
}
return super.canEntityDestroy(state, world, pos, entity);
}
@Override
public boolean rotateBlock(World world, BlockPos pos, Direction axis) {
if (!world.isRemote && getDirection() != null) {
TileBase tile = (TileBase) world.getTileEntity(pos);
Direction newDirection = getDirection().cycle(tile.getDirection());
if (tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable && ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().hasCover(newDirection)) {
return false;
}
}
return super.rotateBlock(world, pos, axis);
}
protected boolean openNetworkGui(int guiId, PlayerEntity player, World world, BlockPos pos, Direction facing) {
return openNetworkGui(guiId, player, world, pos, facing, Permission.MODIFY);
}
protected boolean openNetworkGui(int guiId, PlayerEntity player, World world, BlockPos pos, Direction facing, Permission... permissions) {
return openNetworkGui(player, world, pos, facing, () -> player.openGui(info.getModObject(), guiId, world, pos.getX(), pos.getY(), pos.getZ()), permissions);
}
protected boolean openNetworkGui(PlayerEntity player, World world, BlockPos pos, Direction facing, Runnable action) {
return openNetworkGui(player, world, pos, facing, action, Permission.MODIFY);
}
protected boolean openNetworkGui(PlayerEntity player, World world, BlockPos pos, Direction facing, Runnable action, Permission... permissions) {
if (world.isRemote) {
return true;
}
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, facing)) {
INetworkNodeProxy nodeProxy = CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY.cast(tile.getCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, facing));
INetworkNode node = nodeProxy.getNode();
if (node.getNetwork() != null) {
for (Permission permission : permissions) {
if (!node.getNetwork().getSecurityManager().hasPermission(permission, player)) {
WorldUtils.sendNoPermissionMessage(player);
return true; // Avoid placing blocks
}
}
}
}
action.run();
return true;
}*/
}

View File

@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.container.DiskDriveContainer;
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.raoulvdberge.refinedstorage.tile.DiskDriveTile;
import com.raoulvdberge.refinedstorage.util.BlockUtils;
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
@@ -47,7 +48,7 @@ public class DiskDriveBlock extends NodeBlock {
@SuppressWarnings("deprecation")
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTraceResult) {
if (!world.isRemote) {
NetworkHooks.openGui(
return NetworkUtils.attemptModify(world, pos, rayTraceResult.getFace(), player, () -> NetworkHooks.openGui(
(ServerPlayerEntity) player,
new PositionalTileContainerProvider<DiskDriveTile>(
new TranslationTextComponent("gui.refinedstorage.disk_drive"),
@@ -55,15 +56,9 @@ public class DiskDriveBlock extends NodeBlock {
pos
),
pos
);
));
}
return true;
}
/* TODO
@Override
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
return openNetworkGui(RSGui.DISK_DRIVE, player, world, pos, side);
}*/
}

View File

@@ -76,6 +76,22 @@ public abstract class NodeBlock extends BaseBlock {
}
}
/* TODO - Covers needed for this one
@Override
public boolean rotateBlock(World world, BlockPos pos, Direction axis) {
if (!world.isRemote && getDirection() != null) {
TileBase tile = (TileBase) world.getTileEntity(pos);
Direction newDirection = getDirection().cycle(tile.getDirection());
if (tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable && ((ICoverable) ((TileNode) tile).getNode()).getCoverManager().hasCover(newDirection)) {
return false;
}
}
return super.rotateBlock(world, pos, axis);
}*/
public boolean hasConnectedState() {
return false;
}

View File

@@ -14,11 +14,7 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
private BaseScreen parent;
protected TextFieldWidget amountField;
protected Button okButton;
private Button cancelButton;
private Button[] incrementButtons = new Button[6];
public AmountSpecifyingScreen(BaseScreen parent, T container, int width, int height, PlayerInventory playerInventory, ITextComponent title) {
super(container, width, height, playerInventory, title);
@@ -51,7 +47,7 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
Pair<Integer, Integer> pos = getOkCancelPos();
okButton = addButton(x + pos.getLeft(), y + pos.getRight(), 50, 20, getOkButtonText(), true, true, btn -> onOkButtonPressed(hasShiftDown()));
cancelButton = addButton(x + pos.getLeft(), y + pos.getRight() + 24, 50, 20, I18n.format("gui.cancel"), true, true, btn -> close());
addButton(x + pos.getLeft(), y + pos.getRight() + 24, 50, 20, I18n.format("gui.cancel"), true, true, btn -> close());
amountField = new TextFieldWidget(font, x + getAmountPos().getLeft(), y + getAmountPos().getRight(), 69 - 6, font.FONT_HEIGHT, "");
amountField.setEnableBackgroundDrawing(false);
@@ -79,7 +75,7 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
text = "+1B";
}
incrementButtons[i] = addButton(x + xx, y + 20, width, 20, text, true, true, btn -> onIncrementButtonClicked(increment));
addButton(x + xx, y + 20, width, 20, text, true, true, btn -> onIncrementButtonClicked(increment));
xx += width + 3;
}
@@ -95,7 +91,7 @@ public abstract class AmountSpecifyingScreen<T extends Container> extends BaseSc
text = "-1B";
}
incrementButtons[3 + i] = addButton(x + xx, y + ySize - 20 - 7, width, 20, text, true, true, btn -> onIncrementButtonClicked(-increment));
addButton(x + xx, y + ySize - 20 - 7, width, 20, text, true, true, btn -> onIncrementButtonClicked(-increment));
xx += width + 3;
}

View File

@@ -37,7 +37,7 @@ public class GuiAmount extends AmountSpecifyingScreen<AmountContainer> {
@Override
protected String getOkButtonText() {
return I18n.format("misc.refinedstorage:set");
return I18n.format("misc.refinedstorage.set");
}
@Override

View File

@@ -37,7 +37,7 @@ public class GuiFluidAmount extends AmountSpecifyingScreen<FluidAmountContainer>
@Override
protected String getOkButtonText() {
return I18n.format("misc.refinedstorage:set");
return I18n.format("misc.refinedstorage.set");
}
@Override

View File

@@ -18,7 +18,7 @@ public class PriorityScreen extends AmountSpecifyingScreen<Container> {
public boolean canInteractWith(PlayerEntity player) {
return false;
}
}, 164, 92, inventory, new TranslationTextComponent("misc.refinedstorage:priority"));
}, 164, 92, inventory, new TranslationTextComponent("misc.refinedstorage.priority"));
this.priority = priority;
}
@@ -30,7 +30,7 @@ public class PriorityScreen extends AmountSpecifyingScreen<Container> {
@Override
protected String getOkButtonText() {
return I18n.format("misc.refinedstorage:set");
return I18n.format("misc.refinedstorage.set");
}
@Override

View File

@@ -81,9 +81,9 @@ public class StorageScreen<T extends Container> extends BaseScreen<T> {
addSideButton(new SideButtonAccessType(this, accessTypeParameter));
}
int buttonWidth = 10 + font.getStringWidth(I18n.format("misc.refinedstorage:priority"));
int buttonWidth = 10 + font.getStringWidth(I18n.format("misc.refinedstorage.priority"));
priorityButton = addButton(x + 169 - buttonWidth, y + 41, buttonWidth, 20, I18n.format("misc.refinedstorage:priority"), true, true, btn -> {
priorityButton = addButton(x + 169 - buttonWidth, y + 41, buttonWidth, 20, I18n.format("misc.refinedstorage.priority"), true, true, btn -> {
minecraft.displayGuiScreen(new PriorityScreen(this, priorityParameter, playerInventory));
});
}

View File

@@ -0,0 +1,45 @@
package com.raoulvdberge.refinedstorage.util;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class NetworkUtils {
public static boolean attemptModify(World world, BlockPos pos, Direction facing, PlayerEntity player, Runnable action) {
return attempt(world, pos, facing, player, action, Permission.MODIFY);
}
public static boolean attempt(World world, BlockPos pos, Direction facing, PlayerEntity player, Runnable action, Permission... permissionsRequired) {
if (world.isRemote) {
return true;
}
TileEntity tile = world.getTileEntity(pos);
if (tile != null) {
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, facing).orElse(null);
if (proxy != null) {
INetworkNode node = proxy.getNode();
for (Permission permission : permissionsRequired) {
if (!node.getNetwork().getSecurityManager().hasPermission(permission, player)) {
WorldUtils.sendNoPermissionMessage(player);
return true; // Avoid placing blocks
}
}
}
}
action.run();
return true;
}
}

View File

@@ -103,9 +103,9 @@
"misc.refinedstorage:security.no_permission": "You have no permission to perform that action.",
"misc.refinedstorage:start": "Start",
"misc.refinedstorage:clear": "Clear",
"misc.refinedstorage:set": "Set",
"misc.refinedstorage.set": "Set",
"misc.refinedstorage:cancel_all": "Cancel All",
"misc.refinedstorage:priority": "Priority",
"misc.refinedstorage.priority": "Priority",
"misc.refinedstorage:oredict": "Oredict",
"misc.refinedstorage.processing": "Processing",
"misc.refinedstorage:reader_writer.redstone": "Redstone strength: %d",