Skip to content

Commit

Permalink
facade rendering now uses tesselateBlock, configs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Oct 4, 2024
1 parent ccbd4f1 commit 48a8e28
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 193 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ org.gradle.daemon=false

mod_id=storagenetwork
curse_id=268495
mod_version=1.11.1
mod_version=1.11.2-SNAPSHOT



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public static BlockState cleanBlockState(BlockState state) {

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
TileCable tile = TileCable.getTileCable(worldIn, pos);
if (tile != null
&& ConfigRegistry.facadesUseCollisionBoundingBox.get()
&& tile.getFacadeState() != null) {
return tile.getFacadeState().getShape(worldIn, pos, context);
if (ConfigRegistry.enableFacades.get()) {
TileCable tile = TileCable.getTileCable(worldIn, pos);
if (tile != null && tile.getFacadeState() != null) {
return tile.getFacadeState().getShape(worldIn, pos, context);
}
}
return ShapeCache.getOrCreate(state, ShapeBuilder::createShape);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.lothrazar.storagenetwork.block.cable;

import com.lothrazar.storagenetwork.registry.ConfigRegistry;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexMultiConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.ModelData;

public class CableFacadeRenderer implements BlockEntityRenderer<TileCable> {

private BlockRenderDispatcher brd;
private ModelBlockRenderer renderer;

public CableFacadeRenderer(BlockEntityRendererProvider.Context d) {
this.brd = d.getBlockRenderDispatcher();
this.renderer = brd.getModelRenderer();
}

@Override
public boolean shouldRenderOffScreen(TileCable te) {
return true;
}

@Override
public void render(TileCable te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) {
if (ConfigRegistry.enableFacades.get() && te.getFacadeState() != null) {
BlockState facadeState = te.getFacadeState();
BakedModel model = this.brd.getBlockModel(facadeState);
VertexConsumer vertexConsumer = VertexMultiConsumer.create(ibuffer.getBuffer(RenderType.solid()));
renderer.tesselateBlock(te.getLevel(), model, facadeState, te.getBlockPos(),
matrixStack, vertexConsumer, false, te.getLevel().random, packedLight, packedOverlay,
ModelData.EMPTY, RenderType.solid());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ public void load(CompoundTag compound) {
else {
setFacadeState(null);
}

}

@Override
public void saveAdditional(CompoundTag compound) {
super.saveAdditional(compound);
if (facadeState != null) {
compound.put(NBT_FACADE, facadeState);
compound.put(NBT_FACADE, facadeState);
}
}

Expand All @@ -67,5 +66,4 @@ public BlockState getFacadeState() {
public void setFacadeState(CompoundTag facadeState) {
this.facadeState = facadeState;
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.lwjgl.glfw.GLFW;
import com.lothrazar.storagenetwork.StorageNetworkMod;
import com.lothrazar.storagenetwork.block.facade.TesrCable;
import com.lothrazar.storagenetwork.block.facade.TesrExportCable;
import com.lothrazar.storagenetwork.block.facade.TesrImportCable;
import com.lothrazar.storagenetwork.block.facade.TesrImportFilterCable;
import com.lothrazar.storagenetwork.block.facade.TesrStorageCable;
import com.lothrazar.storagenetwork.block.cable.CableFacadeRenderer;
import com.lothrazar.storagenetwork.registry.SsnRegistry.Tiles;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
Expand All @@ -25,10 +21,10 @@ public class ClientEventRegistry {

@SubscribeEvent
public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(Tiles.KABEL.get(), TesrCable::new);
event.registerBlockEntityRenderer(Tiles.EXPORT_KABEL.get(), TesrExportCable::new);
event.registerBlockEntityRenderer(Tiles.STORAGE_KABEL.get(), TesrStorageCable::new);
event.registerBlockEntityRenderer(Tiles.IMPORT_FILTER_KABEL.get(), TesrImportFilterCable::new);
event.registerBlockEntityRenderer(Tiles.IMPORT_KABEL.get(), TesrImportCable::new);
event.registerBlockEntityRenderer(Tiles.KABEL.get(), CableFacadeRenderer::new);
event.registerBlockEntityRenderer(Tiles.EXPORT_KABEL.get(), CableFacadeRenderer::new);
event.registerBlockEntityRenderer(Tiles.STORAGE_KABEL.get(), CableFacadeRenderer::new);
event.registerBlockEntityRenderer(Tiles.IMPORT_FILTER_KABEL.get(), CableFacadeRenderer::new);
event.registerBlockEntityRenderer(Tiles.IMPORT_KABEL.get(), CableFacadeRenderer::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ConfigRegistry {
public static IntValue ITEMRANGE;
public static IntValue RECIPEMAXTAGS;
private static ConfigValue<List<String>> CABLEIGNORELIST;
public static BooleanValue facadesUseCollisionBoundingBox;
public static BooleanValue enableFacades;
static {
initConfig();
}
Expand Down Expand Up @@ -62,13 +62,25 @@ private static void initConfig() {
RECIPEMAXTAGS = COMMON_BUILDER.comment("\r\n When matching items to recipes in the JEI + button, this is the maximum number of tags to serialize over the network when on a server. Reduce if you get errors relating to Packet Sizes being too large (Minecraft 1.12.2 had this hardcoded at 5).")
.defineInRange("jeiMaximumRecipeTags", 64, 5, 128);
//
list = Arrays.asList("minecraft:golden_rail", "minecraft:ladder", "minecraft:rail", "minecraft:detector_rail", "minecraft:activator_rail",
"minecraft:double_plant",
"minecraft:waterlily");
CABLEIGNORELIST = COMMON_BUILDER.comment("\r\n Disable these blocks from ever being able to connect to the network, they will be treated as a non-inventory.")
.define("BlacklistFacadeCableItems", list);
facadesUseCollisionBoundingBox = COMMON_BUILDER.comment("If this is true, cables with facades will also use the collision block from the block facade (ie stairs, carpet, etc). ")
.define("facadesUseCollisionBoundingBox", true);
COMMON_BUILDER.push("facades");
list = Arrays.asList("minecraft:ladder", "minecraft:double_plant", "minecraft:waterlily",
"minecraft:torch", "minecraft:*_torch", "minecraft:redstone", "minecraft:iron_bars",
"minecraft:chest", "minecraft:ender_chest", "minecraft:sculk_vein", "minecraft:string", "minecraft:vine",
"minecraft:rail",
"minecraft:*_rail",
"minecraft:brewing_stand",
"minecraft:*_dripleaf",
"minecraft:*_pane",
"minecraft:*_sapling", "minecraft:*_sign",
"minecraft:*_door",
"minecraft:*_banner", "minecraft:*_shulker_box",
"cyclic:*_pipe", "cyclic:*_bars",
"storagenetwork:*");
CABLEIGNORELIST = COMMON_BUILDER.comment("\r\n These items are not able to be used as Facade blocks for cables (shift-left-click to add or remove block facades while in not-creative)")
.define("itemsNotAllowed", list);
enableFacades = COMMON_BUILDER.comment("Change this to 'false' to disable facades. The facade feature lets you hide cables with blocks (does not consume the item, use shift-left-click when not creative)")
.define("enabled", true);
COMMON_BUILDER.pop();
COMMON_BUILDER.pop();
COMMON_CONFIG = COMMON_BUILDER.build();
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/lothrazar/storagenetwork/registry/SsnEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public void onEntityItemPickupEvent(EntityItemPickupEvent event) {
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
ItemBuilder.onLeftClickBlock(event);
if (ConfigRegistry.enableFacades.get()) {
onHitFacadeHandler(event);
}
}

private void onHitFacadeHandler(PlayerInteractEvent.LeftClickBlock event) {
Level level = event.getLevel();
if (!level.isClientSide) {
return;
Expand All @@ -45,19 +50,18 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) {
else {
Block block = Block.byItem(held.getItem());
if (block == null || block == Blocks.AIR) {
StorageNetworkMod.log("no block");
return;
}
if (!ConfigRegistry.isFacadeAllowed(held)) {
StorageNetworkMod.log("not allowed as a facade from config file");
StorageNetworkMod.log("not allowed as a facade from config file: " + held.getItem());
return;
}
BlockHitResult bhr = (BlockHitResult) player.pick(5, 1, false);
//pick the block, write to tags, and send to server
boolean pickFluids = false;
BlockHitResult bhr = (BlockHitResult) player.pick(player.getBlockReach(), 1, pickFluids);
BlockPlaceContext context = new BlockPlaceContext(player, event.getHand(), held, bhr);

BlockState facadeState = null;
facadeState = block.getStateForPlacement(context);
CompoundTag tags = NbtUtils.writeBlockState(facadeState);
BlockState facadeState = block.getStateForPlacement(context);
CompoundTag tags = (facadeState == null) ? null : NbtUtils.writeBlockState(facadeState);
PacketRegistry.INSTANCE.sendToServer(new CableFacadeMessage(event.getPos(), tags));
}
}
Expand All @@ -70,5 +74,4 @@ public void onKeyInput(InputEvent.Key event) {
PacketRegistry.INSTANCE.sendToServer(new KeybindCurioMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ public static class Tiles {
public static final RegistryObject<BlockEntityType<TileCableExport>> EXPORT_KABEL = TILES.register("export_kabel", () -> BlockEntityType.Builder.of(TileCableExport::new, Blocks.EXPORT_KABEL.get()).build(null));
public static final RegistryObject<BlockEntityType<TileExchange>> EXCHANGE = TILES.register("exchange", () -> BlockEntityType.Builder.of(TileExchange::new, Blocks.EXCHANGE.get()).build(null));
public static final RegistryObject<BlockEntityType<TileCollection>> COLLECTOR = TILES.register("collector", () -> BlockEntityType.Builder.of(TileCollection::new, Blocks.COLLECTOR.get()).build(null));


}


@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class Menus {

Expand Down
1 change: 1 addition & 0 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

,"1.11.1":"The Storage Request Table 'storagenetwork:request' block no longer saves the contents of its crafting-grid; instead items are returned to the player on close, exactly matching vanilla crafting table behavior (this was changed to prevent potential exploits. If any items are left behind in the grid during world upgrade they will be returned and not lost. No changes were made to the remotes or to other blocks). Fixed a null pointer exception "

,"1.11.2":"Ported the Cable Facades feature (from Minecraft 1.12.2), so that you can shift-left-click with a block on a cable to hide it with a facade. Disable this feature or ignore cretain blocks with the config file"
}
}

0 comments on commit 48a8e28

Please sign in to comment.