Cables can now be covered. Thanks to vhd. Closes #1954

This commit is contained in:
vhd 2020-01-10 17:07:02 +02:00 committed by drcrazy
parent a115fbd736
commit d1b395f3e4
16 changed files with 277 additions and 52 deletions

View file

@ -47,6 +47,7 @@ import reborncore.client.hud.StackInfoHUD;
import reborncore.client.multiblock.MultiblockRenderer;
import techreborn.client.render.DynamicBucketBakedModel;
import techreborn.client.render.DynamicCellBakedModel;
import techreborn.client.render.entitys.CableCoverEntityRenderer;
import techreborn.client.render.entitys.StorageUnitEntityRenderer;
import techreborn.events.StackToolTipHandler;
import techreborn.init.ModFluids;
@ -156,6 +157,7 @@ public class TechRebornClient implements ClientModInitializer {
BlockEntityRendererRegistry.INSTANCE.register(TRBlockEntities.IMPLOSION_COMPRESSOR, MultiblockRenderer::new);
BlockEntityRendererRegistry.INSTANCE.register(TRBlockEntities.GREENHOUSE_CONTROLLER, MultiblockRenderer::new);
BlockEntityRendererRegistry.INSTANCE.register(TRBlockEntities.STORAGE_UNIT, StorageUnitEntityRenderer::new);
BlockEntityRendererRegistry.INSTANCE.register(TRBlockEntities.CABLE, CableCoverEntityRenderer::new);
}

View file

@ -29,11 +29,13 @@ import java.util.Collections;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
@ -42,6 +44,8 @@ import net.minecraft.util.math.Direction;
import org.apache.commons.lang3.tuple.Pair;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
import reborncore.common.network.ClientBoundPackets;
import reborncore.common.network.NetworkManager;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.StringUtils;
@ -63,6 +67,7 @@ public class CableBlockEntity extends BlockEntity
private double energy = 0;
private TRContent.Cables cableType = null;
private ArrayList<EnergySide> sendingFace = new ArrayList<>();
private BlockState cover = null;
public CableBlockEntity() {
super(TRBlockEntities.CABLE);
@ -107,12 +112,20 @@ public class CableBlockEntity extends BlockEntity
if (compound.contains("energy")) {
energy = compound.getDouble("energy");
}
if (compound.contains("cover")) {
cover = NbtHelper.toBlockState(compound.getCompound("cover"));
} else {
cover = null;
}
}
@Override
public CompoundTag toTag(CompoundTag compound) {
super.toTag(compound);
compound.putDouble("energy", energy);
if (cover != null) {
compound.put("cover", NbtHelper.fromBlockState(cover));
}
return compound;
}
@ -166,6 +179,9 @@ public class CableBlockEntity extends BlockEntity
+ PowerSystem.getLocaliszedPowerFormatted(getCableType().transferRate) + "/t"));
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.tier") + ": "
+ Formatting.GOLD + StringUtils.toFirstCapitalAllLowercase(getCableType().tier.toString())));
if (!getCableType().canKill) {
info.add(new LiteralText(Formatting.GRAY + StringUtils.t("techreborn.tooltip.cable.can_cover")));
}
}
// IToolDrop
@ -232,4 +248,16 @@ public class CableBlockEntity extends BlockEntity
public void setStored(double amount) {
this.energy = amount;
}
public BlockState getCover() {
return cover;
}
public void setCover(BlockState cover) {
this.cover = cover;
if (!world.isClient) {
NetworkManager.sendToTracking(ClientBoundPackets.createCustomDescriptionPacket(this), this);
}
}
}

View file

@ -24,23 +24,20 @@
package techreborn.blocks.cable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.Material;
import net.minecraft.block.Waterloggable;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.AbstractProperty;
import net.minecraft.state.property.BooleanProperty;
@ -52,6 +49,7 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
@ -81,6 +79,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
public static final BooleanProperty UP = BooleanProperty.of("up");
public static final BooleanProperty DOWN = BooleanProperty.of("down");
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final BooleanProperty COVERED = BooleanProperty.of("covered");
public static final Map<Direction, BooleanProperty> PROPERTY_MAP = Util.make(new HashMap<>(), map -> {
map.put(Direction.EAST, EAST);
@ -98,7 +97,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
super(Block.Settings.of(Material.STONE).strength(1f, 8f));
this.type = type;
setDefaultState(this.getStateManager().getDefaultState().with(EAST, false).with(WEST, false).with(NORTH, false)
.with(SOUTH, false).with(UP, false).with(DOWN, false).with(WATERLOGGED, false));
.with(SOUTH, false).with(UP, false).with(DOWN, false).with(WATERLOGGED, false).with(COVERED, false));
BlockWrenchEventHandler.wrenableBlocks.add(this);
cableShapeUtil = new CableShapeUtil(this);
}
@ -166,16 +165,34 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
}
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
if (state.get(COVERED) && !playerIn.isSneaking()) {
((CableBlockEntity) blockEntity).setCover(null);
worldIn.setBlockState(pos, state.with(COVERED, false));
worldIn.playSound(playerIn, pos, SoundEvents.BLOCK_WOOD_BREAK, SoundCategory.BLOCKS, 0.6F, 1.0F);
return ActionResult.SUCCESS;
}
if (WrenchUtils.handleWrench(stack, worldIn, pos, playerIn, hitResult.getSide())) {
return ActionResult.SUCCESS;
}
}
if (!stack.isEmpty() && !state.get(COVERED) && !state.get(WATERLOGGED) && !type.canKill
&& stack.getItem() == TRContent.Plates.WOOD.asItem()) {
worldIn.setBlockState(pos, state.with(COVERED, true));
worldIn.playSound(playerIn, pos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 0.6F, 1.0F);
if (!worldIn.isClient) {
stack.decrement(1);
}
return ActionResult.SUCCESS;
}
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(EAST, WEST, NORTH, SOUTH, UP, DOWN, WATERLOGGED);
builder.add(EAST, WEST, NORTH, SOUTH, UP, DOWN, WATERLOGGED, COVERED);
}
@Override
@ -196,6 +213,9 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, EntityContext entityContext) {
if (state.get(COVERED)) {
return VoxelShapes.fullCube();
}
return cableShapeUtil.getShape(state);
}
@ -237,6 +257,16 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
}
}
@Override
public boolean tryFillWithFluid(IWorld world, BlockPos pos, BlockState state, FluidState fluidState) {
return !state.get(COVERED) && Waterloggable.super.tryFillWithFluid(world, pos, state, fluidState);
}
@Override
public boolean canFillWithFluid(BlockView view, BlockPos pos, BlockState state, Fluid fluid) {
return !state.get(COVERED) && Waterloggable.super.canFillWithFluid(view, pos, state, fluid);
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);

View file

@ -0,0 +1,39 @@
package techreborn.client.render.entitys;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import techreborn.blockentity.cable.CableBlockEntity;
import techreborn.blocks.cable.CableBlock;
import java.util.Random;
public class CableCoverEntityRenderer extends BlockEntityRenderer<CableBlockEntity> {
public CableCoverEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher);
}
@Override
public void render(CableBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (blockEntity.getWorld() == null) {
return;
}
if (!blockEntity.getWorld().getBlockState(blockEntity.getPos()).get(CableBlock.COVERED)) {
return;
}
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
BlockState blockState = blockEntity.getCover() != null ? blockEntity.getCover() : Blocks.OAK_PLANKS.getDefaultState();
VertexConsumer consumer = vertexConsumers.getBuffer(RenderLayers.getBlockLayer(blockState));
blockRenderManager.renderBlock(blockState, blockEntity.getPos(), blockEntity.getWorld(), matrices, consumer, true, new Random());
}
}

View file

@ -65,6 +65,7 @@ import techreborn.items.armor.ItemQuantumSuit;
import techreborn.items.armor.ItemTRArmour;
import techreborn.items.battery.*;
import techreborn.items.tool.DebugToolItem;
import techreborn.items.tool.PaintingToolItem;
import techreborn.items.tool.TreeTapItem;
import techreborn.items.tool.WrenchItem;
import techreborn.items.tool.advanced.AdvancedChainsawItem;
@ -206,6 +207,7 @@ public class ModRegistry {
// Tools
RebornRegistry.registerItem(TRContent.TREE_TAP = InitUtils.setup(new TreeTapItem(), "treetap"));
RebornRegistry.registerItem(TRContent.WRENCH = InitUtils.setup(new WrenchItem(), "wrench"));
RebornRegistry.registerItem(TRContent.PAINTING_TOOL = InitUtils.setup(new PaintingToolItem(), "painting_tool"));
RebornRegistry.registerItem(TRContent.BASIC_DRILL = InitUtils.setup(new BasicDrillItem(), "basic_drill"));
RebornRegistry.registerItem(TRContent.BASIC_CHAINSAW = InitUtils.setup(new BasicChainsawItem(), "basic_chainsaw"));

View file

@ -124,6 +124,7 @@ public class TRContent {
// Tools
public static Item TREE_TAP;
public static Item WRENCH;
public static Item PAINTING_TOOL;
public static Item BASIC_CHAINSAW;
public static Item BASIC_DRILL;

View file

@ -0,0 +1,88 @@
package techreborn.items.tool;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.world.World;
import techreborn.TechReborn;
import techreborn.blockentity.cable.CableBlockEntity;
import techreborn.blocks.cable.CableBlock;
import javax.annotation.Nullable;
import java.util.List;
public class PaintingToolItem extends Item {
public PaintingToolItem() {
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamageIfAbsent(64));
}
public ActionResult useOnBlock(ItemUsageContext context) {
PlayerEntity player = context.getPlayer();
if (player == null) {
return ActionResult.FAIL;
}
BlockState blockState = context.getWorld().getBlockState(context.getBlockPos());
if (player.isSneaking()) {
if (blockState.isSimpleFullBlock(context.getWorld(), context.getBlockPos())
&& blockState.getBlock().getDefaultState().isSimpleFullBlock(context.getWorld(), context.getBlockPos())) {
context.getStack().getOrCreateTag().put("cover", NbtHelper.fromBlockState(blockState));
return ActionResult.SUCCESS;
}
return ActionResult.FAIL;
} else {
BlockState cover = getCover(context.getStack());
if (cover != null && blockState.getBlock() instanceof CableBlock && blockState.get(CableBlock.COVERED)) {
BlockEntity blockEntity = context.getWorld().getBlockEntity(context.getBlockPos());
if (blockEntity == null) {
return ActionResult.FAIL;
}
((CableBlockEntity) blockEntity).setCover(cover);
context.getWorld().playSound(player, context.getBlockPos(), SoundEvents.BLOCK_WOOL_PLACE, SoundCategory.BLOCKS, 0.6F, 1.0F);
if (!context.getWorld().isClient) {
context.getStack().damage(1, player, playerCb -> {
playerCb.sendToolBreakStatus(context.getHand());
});
}
return ActionResult.SUCCESS;
}
}
return ActionResult.FAIL;
}
public static BlockState getCover(ItemStack stack) {
if (stack.hasTag() && stack.getTag().contains("cover")) {
return NbtHelper.toBlockState(stack.getTag().getCompound("cover"));
}
return null;
}
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
BlockState blockState = getCover(stack);
if (blockState != null) {
tooltip.add((new TranslatableText(blockState.getBlock().getTranslationKey())).formatted(Formatting.GRAY));
tooltip.add((new TranslatableText("techreborn.tooltip.painting_tool.apply")).formatted(Formatting.GOLD));
} else {
tooltip.add((new TranslatableText("techreborn.tooltip.painting_tool.select")).formatted(Formatting.GOLD));
}
}
}

View file

@ -1,32 +1,31 @@
{
"multipart": [
{
"apply": {
"model": "techreborn:block/cable/glassfiber_cable_core"
}
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_core" }
},
{
"when": { "north": "true" },
"when": { "north": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side" }
},
{
"when": { "east": "true" },
"when": { "east": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 90 }
},
{
"when": { "south": "true" },
"when": { "south": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 180 }
},
{
"when": { "west": "true" },
"when": { "west": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 270 }
},
{
"when": { "up": "true" },
"when": { "up": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "x": 270}
},
{
"when": { "down": "true" },
"when": { "down": true, "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "x": 90 }
}
]

View file

@ -1,30 +1,31 @@
{
"multipart": [
{
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_core" }
},
{
"when": { "north": true },
"when": { "north": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side" }
},
{
"when": { "east": true },
"when": { "east": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 90 }
},
{
"when": { "south": true },
"when": { "south": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 180 }
},
{
"when": { "west": true },
"when": { "west": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 270 }
},
{
"when": { "up": true },
"when": { "up": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "x": 270}
},
{
"when": { "down": true },
"when": { "down": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "x": 90 }
}
]

View file

@ -1,30 +1,31 @@
{
"multipart": [
{
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_core" }
},
{
"when": { "north": true },
"when": { "north": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side" }
},
{
"when": { "east": true },
"when": { "east": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 90 }
},
{
"when": { "south": true },
"when": { "south": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 180 }
},
{
"when": { "west": true },
"when": { "west": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 270 }
},
{
"when": { "up": true },
"when": { "up": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "x": 270}
},
{
"when": { "down": true },
"when": { "down": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "x": 90 }
}
]

View file

@ -1,30 +1,31 @@
{
"multipart": [
{
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_core" }
},
{
"when": { "north": true },
"when": { "north": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side" }
},
{
"when": { "east": true },
"when": { "east": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 90 }
},
{
"when": { "south": true },
"when": { "south": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 180 }
},
{
"when": { "west": true },
"when": { "west": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 270 }
},
{
"when": { "up": true },
"when": { "up": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "x": 270}
},
{
"when": { "down": true },
"when": { "down": true, "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "x": 90 }
}
]

View file

@ -1,30 +1,31 @@
{
"multipart": [
{
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_core" }
},
{
"when": { "north": true },
"when": { "north": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side" }
},
{
"when": { "east": true },
"when": { "east": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 90 }
},
{
"when": { "south": true },
"when": { "south": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 180 }
},
{
"when": { "west": true },
"when": { "west": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 270 }
},
{
"when": { "up": true },
"when": { "up": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side", "x": 270}
},
{
"when": { "down": true },
"when": { "down": true, "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side", "x": 90 }
}
]

View file

@ -547,6 +547,7 @@
"item.techreborn.treetap": "Treetap",
"item.techreborn.wrench": "Wrench",
"item.techreborn.destructopack": "Destructopack",
"item.techreborn.painting_tool": "Painting Tool",
"_comment17": "Items-Misc",
"item.techreborn.cell": "Empty Cell",
@ -726,6 +727,9 @@
"techreborn.tooltip.unit.capacity": "Capacity: ",
"techreborn.tooltip.unit.empty": "Empty",
"techreborn.tooltip.unit.divider": " of ",
"techreborn.tooltip.painting_tool.select": "Shift right click on block to set style",
"techreborn.tooltip.painting_tool.apply": "Right click on covered cable to apply",
"techreborn.tooltip.cable.can_cover": "Can be covered with wooden plates",
"_comment23": "ManualUI",
"techreborn.manual.wiki": "Online wiki",

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/tool/painting_tool"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,22 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"BWB",
"NBN",
" B "
],
"key": {
"B": {
"item": "techreborn:bronze_ingot"
},
"N": {
"item": "techreborn:bronze_nugget"
},
"W": {
"tag": "minecraft:wool"
}
},
"result": {
"item": "techreborn:painting_tool"
}
}