Finalized linking tool functionality

This commit is contained in:
Buuz135 2021-12-24 17:15:57 +01:00
parent 53d75d44df
commit 4a0125df2d
11 changed files with 158 additions and 23 deletions

View File

@ -22,6 +22,7 @@ java {
minecraft {
mappings channel: 'official', version: '1.18.1'
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs {
client {

View File

@ -25,7 +25,7 @@ a50aeb3877dd4003bb3ed359fccde1f3674bc028 assets/functionalstorage/blockstates/sp
fbf8ebd85350f3b4ad0bf6faf51f9ecf0677bf5b assets/functionalstorage/blockstates/warped_1.json
bcd4b5e128d5175bea44ecae340aeec86cd5a123 assets/functionalstorage/blockstates/warped_2.json
ebc4aebffb44baa4dd507078b9fd3c74e881f4c1 assets/functionalstorage/blockstates/warped_4.json
9dd6f6257a11b65464b17d9ee2fd5502afe13548 assets/functionalstorage/lang/en_us.json
9d530c2208153d2bd3dd18669fa446e6c625fdf5 assets/functionalstorage/lang/en_us.json
68c3f6a8fe55202f83c0fcdd6c8ca10ef88019ef assets/functionalstorage/models/block/acacia_1_locked.json
c7d0376ba2a080ba12c344369ad11538899db176 assets/functionalstorage/models/block/acacia_2_locked.json
79b86baeec4aa6784aa52028d2f3bc98ddab8c14 assets/functionalstorage/models/block/acacia_4_locked.json
@ -112,5 +112,5 @@ ff234dac4f0b0b4f83ffa92f2d2fb1074c68df43 data/functionalstorage/recipes/spruce_4
bcb281904eac23183c45786e3d703d24bba92be6 data/functionalstorage/recipes/warped_1.json
8fc3f76a2c57eb4d80ce86947fabebe48fa6f692 data/functionalstorage/recipes/warped_2.json
7510a8ca1f1e3bb63f4c4f4add0bb6b713feaa0b data/functionalstorage/recipes/warped_4.json
0f4c6dba10677b5d217ee704be3d1deb92517fad data/functionalstorage/tags/items/drawer.json
d02963f7da0ca8877113c80cb1dd49d60069ff78 data/functionalstorage/tags/items/drawer.json
12ec935226bf5a6a1493d353ef6dc6c224c256dd data/functionalstorage/tags/items/ignore_crafting_check.json

View File

@ -27,6 +27,7 @@
"block.functionalstorage.warped_2": "Warped Drawer (1x2)",
"block.functionalstorage.warped_4": "Warped Drawer (2x2)",
"item.functionalstorage.collector_upgrade": "Collector Upgrade",
"item.functionalstorage.configuration_tool": "Configuration Tool",
"item.functionalstorage.copper_upgrade": "Copper Upgrade",
"item.functionalstorage.diamond_upgrade": "Diamond Upgrade",
"item.functionalstorage.gold_upgrade": "Gold Upgrade",
@ -51,6 +52,6 @@
"linkingtool.linkingmode.multiple.desc": "Links multiple drawers between 2 points",
"linkingtool.linkingmode.single": "Single",
"linkingtool.linkingmode.single.desc": "Links a drawer to a controller",
"linkingtool.use": "Sneak + Right Click in the air to change modes. Right Click in the air to change actions. Right click a controller to setup the tool then use it nearby drawers to link.",
"linkingtool.use": "Sneak + Right Click in the air to change modes. \nRight Click in the air to change actions. \nRight click a controller to setup the tool then use it nearby drawers to link. \n\nWhile holding the tool it will show the connected drawers to the selected controller.",
"storageupgrade.desc": "Multiplies the block storage by "
}

View File

@ -1,14 +1,14 @@
{
"replace": false,
"values": [
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1",
"functionalstorage:oak_4",
"functionalstorage:spruce_4",
"functionalstorage:birch_4",
"functionalstorage:jungle_4",
"functionalstorage:acacia_4",
"functionalstorage:dark_oak_4",
"functionalstorage:crimson_4",
"functionalstorage:warped_4",
"functionalstorage:oak_2",
"functionalstorage:spruce_2",
"functionalstorage:birch_2",
@ -17,13 +17,13 @@
"functionalstorage:dark_oak_2",
"functionalstorage:crimson_2",
"functionalstorage:warped_2",
"functionalstorage:oak_4",
"functionalstorage:spruce_4",
"functionalstorage:birch_4",
"functionalstorage:jungle_4",
"functionalstorage:acacia_4",
"functionalstorage:dark_oak_4",
"functionalstorage:crimson_4",
"functionalstorage:warped_4"
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1"
]
}

View File

@ -5,6 +5,7 @@ import com.buuz135.functionalstorage.block.CompactingDrawerBlock;
import com.buuz135.functionalstorage.block.DrawerBlock;
import com.buuz135.functionalstorage.block.DrawerControllerBlock;
import com.buuz135.functionalstorage.client.CompactingDrawerRenderer;
import com.buuz135.functionalstorage.client.ControllerRenderer;
import com.buuz135.functionalstorage.client.DrawerRenderer;
import com.buuz135.functionalstorage.data.FunctionalStorageBlockstateProvider;
import com.buuz135.functionalstorage.data.FunctionalStorageLangProvider;
@ -149,7 +150,7 @@ public class FunctionalStorage extends ModuleController {
});
}
registerRenderers.registerBlockEntityRenderer(((BasicTileBlock)COMPACTING_DRAWER.get()).getTileEntityType(), p_173571_ -> new CompactingDrawerRenderer());
registerRenderers.registerBlockEntityRenderer(((BasicTileBlock)DRAWER_CONTROLLER.get()).getTileEntityType(), p -> new ControllerRenderer());
}).subscribe();
EventManager.mod(ColorHandlerEvent.Item.class).process(item -> {
item.getItemColors().register((stack, tint) -> {

View File

@ -80,8 +80,10 @@ public class CompactingDrawerTile extends ControllableDrawerTile<CompactingDrawe
}
public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) {
ItemStack stack = playerIn.getItemInHand(hand);
if (stack.getItem().equals(FunctionalStorage.CONFIGURATION_TOOL.get()) || stack.getItem().equals(FunctionalStorage.LINKING_TOOL.get())) return InteractionResult.PASS;
if (!handler.isSetup() && slot != -1){
ItemStack stack = playerIn.getItemInHand(hand).copy();
stack = playerIn.getItemInHand(hand).copy();
stack.setCount(1);
CompactingUtil compactingUtil = new CompactingUtil(this.level);
compactingUtil.setup(stack);

View File

@ -12,6 +12,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
@ -96,6 +97,10 @@ public class DrawerControllerTile extends ControllableDrawerTile<DrawerControlle
return this;
}
public ConnectedDrawers getConnectedDrawers() {
return connectedDrawers;
}
public void addConnectedDrawers(LinkingToolItem.ActionMode action, BlockPos... positions){
for (BlockPos position : positions) {
if (this.getBlockPos().closerThan(position, 8)){
@ -175,4 +180,9 @@ public class DrawerControllerTile extends ControllableDrawerTile<DrawerControlle
return handlers;
}
}
@Override
public AABB getRenderBoundingBox() {
return super.getRenderBoundingBox().inflate(50);
}
}

View File

@ -0,0 +1,89 @@
package com.buuz135.functionalstorage.client;
import com.buuz135.functionalstorage.block.tile.DrawerControllerTile;
import com.buuz135.functionalstorage.item.LinkingToolItem;
import com.hrznstudio.titanium.util.RayTraceUtils;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.OptionalDouble;
import static com.buuz135.functionalstorage.item.LinkingToolItem.NBT_CONTROLLER;
import static com.buuz135.functionalstorage.item.LinkingToolItem.NBT_FIRST;
public class ControllerRenderer implements BlockEntityRenderer<DrawerControllerTile> {
public static RenderType TYPE = RenderType.create("custom_lines", DefaultVertexFormat.POSITION_COLOR_NORMAL, VertexFormat.Mode.LINES, 256, false, false,RenderType.CompositeState.builder()
.setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getRendertypeLinesShader))
.setDepthTestState(new RenderStateShard.DepthTestStateShard("always", 519))
.setLineState(new RenderStateShard.LineStateShard(OptionalDouble.empty()))
.setLayeringState(new RenderStateShard.LayeringStateShard("view_offset_z_layering", () -> {
PoseStack posestack = RenderSystem.getModelViewStack();
posestack.pushPose();
posestack.scale(0.99975586F, 0.99975586F, 0.99975586F);
RenderSystem.applyModelViewMatrix();
}, () -> {
PoseStack posestack = RenderSystem.getModelViewStack();
posestack.popPose();
RenderSystem.applyModelViewMatrix();
}))
.setCullState(new RenderStateShard.CullStateShard(false))
.createCompositeState(false));
@Override
public void render(DrawerControllerTile tile, float partialTicks, PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = Minecraft.getInstance().player.getMainHandItem();
if (stack.isEmpty()) return;
if (stack.getItem() instanceof LinkingToolItem){
CompoundTag controllerNBT = stack.getOrCreateTag().getCompound(NBT_CONTROLLER);
BlockPos controller = new BlockPos(controllerNBT.getInt("X"), controllerNBT.getInt("Y"), controllerNBT.getInt("Z"));
if (!controller.equals(tile.getBlockPos())) return;
if (stack.getOrCreateTag().contains(NBT_FIRST)){
CompoundTag firstpos = stack.getOrCreateTag().getCompound(NBT_FIRST);
BlockPos firstPos = new BlockPos(firstpos.getInt("X"), firstpos.getInt("Y"), firstpos.getInt("Z"));
HitResult result = RayTraceUtils.rayTraceSimple(Minecraft.getInstance().level, Minecraft.getInstance().player, 8, partialTicks);
if (result.getType() == HitResult.Type.BLOCK){
BlockPos hit = ((BlockHitResult)result).getBlockPos();
AABB aabb = new AABB(Math.min(firstPos.getX(), hit.getX()),Math.min(firstPos.getY(), hit.getY()),Math.min(firstPos.getZ(), hit.getZ()), Math.max(firstPos.getX(), hit.getX()) + 1,Math.max(firstPos.getY(), hit.getY())+1,Math.max(firstPos.getZ(), hit.getZ())+1) ;
VoxelShape shape = Shapes.create(aabb);
LevelRenderer.renderVoxelShape(matrixStack, bufferIn.getBuffer(TYPE), shape, -controller.getX(), -controller.getY(), -controller.getZ(), 1f, 1f, 1f, 1f);
return;
}
}
VoxelShape shape = Shapes.create(new AABB(tile.getBlockPos()));
for (Long connectedDrawer : tile.getConnectedDrawers().getConnectedDrawers()) {
shape = Shapes.join(shape, Shapes.create(new AABB(BlockPos.of(connectedDrawer))), BooleanOp.OR);
}
LevelRenderer.renderVoxelShape(matrixStack, bufferIn.getBuffer(TYPE), shape, -tile.getBlockPos().getX(), -tile.getBlockPos().getY(), -tile.getBlockPos().getZ(), 1f, 1f, 1f, 1f);
}
}
@Override
public boolean shouldRender(DrawerControllerTile p_173568_, Vec3 p_173569_) {
return true;
}
@Override
public boolean shouldRenderOffScreen(DrawerControllerTile p_112306_) {
return true;
}
}

View File

@ -32,7 +32,7 @@ public class FunctionalStorageLangProvider extends LanguageProvider {
this.add("linkingtool.linkingmode.multiple.desc", "Links multiple drawers between 2 points");
this.add("linkingtool.controller", "Controller: ");
this.add("linkingtool.linkingaction", "Linking Action: ");
this.add("linkingtool.use", "Sneak + Right Click in the air to change modes. Right Click in the air to change actions. Right click a controller to setup the tool then use it nearby drawers to link.");
this.add("linkingtool.use", "Sneak + Right Click in the air to change modes. \nRight Click in the air to change actions. \nRight click a controller to setup the tool then use it nearby drawers to link. \n\nWhile holding the tool it will show the connected drawers to the selected controller.");
this.add("linkingtool.linkingaction.add", "Add");
this.add("linkingtool.linkingaction.remove", "Remove");
this.add("key.categories.utility", "Utility");
@ -48,6 +48,7 @@ public class FunctionalStorageLangProvider extends LanguageProvider {
this.add(FunctionalStorage.PUSHING_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.PUSHING_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) );
this.add(FunctionalStorage.VOID_UPGRADE.get(), WordUtils.capitalize(FunctionalStorage.VOID_UPGRADE.get().getRegistryName().getPath().replace('_', ' ').toLowerCase()) );
this.add(FunctionalStorage.ARMORY_CABINET.get(), "Armory Cabinet");
this.add(FunctionalStorage.CONFIGURATION_TOOL.get(), "Configuration Tool");
this.add("item.utility.downgrade", "Downgrades the slots to a max of 64 items");
this.add("item.utility.direction", "Direction: ");
this.add("item.utility.direction.desc", "Right click in a GUI to change direction");

View File

@ -24,9 +24,11 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -35,6 +37,7 @@ public class LinkingToolItem extends BasicItem {
public static final String NBT_MODE = "Mode";
public static final String NBT_CONTROLLER = "Controller";
public static final String NBT_ACTION = "Action";
public static final String NBT_FIRST = "First";
public LinkingToolItem() {
super(new Properties().tab(FunctionalStorage.TAB).stacksTo(1));
@ -84,7 +87,21 @@ public class LinkingToolItem extends BasicItem {
((ControllableDrawerTile<?>) blockEntity).setControllerPos(controller.getBlockPos());
((DrawerControllerTile) controller).addConnectedDrawers(linkingAction, pos);
context.getPlayer().displayClientMessage(new TextComponent("Linked drawer to the controller").setStyle(Style.EMPTY.withColor(linkingMode.color)), true);
}//TODO add to the drawer
}else{
if (stack.getOrCreateTag().contains(NBT_FIRST)){
CompoundTag firstpos = stack.getOrCreateTag().getCompound(NBT_FIRST);
BlockPos firstPos = new BlockPos(firstpos.getInt("X"), firstpos.getInt("Y"), firstpos.getInt("Z"));
AABB aabb = new AABB(Math.min(firstPos.getX(), pos.getX()),Math.min(firstPos.getY(), pos.getY()),Math.min(firstPos.getZ(), pos.getZ()), Math.max(firstPos.getX(), pos.getX()) + 1,Math.max(firstPos.getY(), pos.getY())+1,Math.max(firstPos.getZ(), pos.getZ())+1) ;
((DrawerControllerTile) controller).addConnectedDrawers(linkingAction, getBlockPosInAABB(aabb).toArray(BlockPos[]::new));
stack.getOrCreateTag().remove(NBT_FIRST);
} else {
CompoundTag firstPos = new CompoundTag();
firstPos.putInt("X", pos.getX());
firstPos.putInt("Y", pos.getY());
firstPos.putInt("Z", pos.getZ());
stack.getOrCreateTag().put(NBT_FIRST, firstPos);
}
}
context.getPlayer().playSound(SoundEvents.ITEM_FRAME_ROTATE_ITEM, 0.5f, 1);
return InteractionResult.SUCCESS;
}
@ -146,6 +163,18 @@ public class LinkingToolItem extends BasicItem {
}
}
public static List<BlockPos> getBlockPosInAABB(AABB axisAlignedBB) {
List<BlockPos> blocks = new ArrayList<>();
for (double y = axisAlignedBB.minY; y < axisAlignedBB.maxY; ++y) {
for (double x = axisAlignedBB.minX; x < axisAlignedBB.maxX; ++x) {
for (double z = axisAlignedBB.minZ; z < axisAlignedBB.maxZ; ++z) {
blocks.add(new BlockPos(x, y, z));
}
}
}
return blocks;
}
@Override
public boolean hasTooltipDetails(@Nullable BasicItem.Key key) {
return key == null;

View File

@ -0,0 +1 @@
public net.minecraft.client.renderer.RenderStateShard$LineStateShard