forked from ModFest/glowcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
401 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/dev/hephaestus/glowcase/block/WireframeBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dev.hephaestus.glowcase.block; | ||
|
||
import dev.hephaestus.glowcase.Glowcase; | ||
import dev.hephaestus.glowcase.block.entity.WireframeBlockEntity; | ||
import net.minecraft.block.BlockEntityProvider; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.component.type.NbtComponent; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.tooltip.TooltipType; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.ItemActionResult; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class WireframeBlock extends GlowcaseBlock implements BlockEntityProvider { | ||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new WireframeBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { | ||
if (world.isClient && placer instanceof PlayerEntity player && canEditGlowcase(player, pos)) { | ||
//load any ctrl-picked NBT clientside | ||
NbtComponent blockEntityTag = stack.get(DataComponentTypes.BLOCK_ENTITY_DATA); | ||
if (blockEntityTag != null && world.getBlockEntity(pos) instanceof WireframeBlockEntity be) { | ||
blockEntityTag.applyToBlockEntity(be, world.getRegistryManager()); | ||
} | ||
|
||
Glowcase.proxy.openWireframeBlockEditScreen(pos); | ||
} | ||
} | ||
|
||
@Override | ||
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (!(world.getBlockEntity(pos) instanceof WireframeBlockEntity be)) return ItemActionResult.CONSUME; | ||
|
||
if (world.isClient && player.getStackInHand(hand).isIn(Glowcase.ITEM_TAG) && canEditGlowcase(player, pos)) { | ||
Glowcase.proxy.openWireframeBlockEditScreen(pos); | ||
} | ||
|
||
return ItemActionResult.SUCCESS; | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List<Text> tooltip, TooltipType options) { | ||
tooltip.add(Text.translatable("block.glowcase.wireframe_block.tooltip.0").formatted(Formatting.GRAY)); | ||
tooltip.add(Text.translatable("block.glowcase.generic.tooltip").formatted(Formatting.DARK_GRAY)); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/dev/hephaestus/glowcase/block/entity/WireframeBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package dev.hephaestus.glowcase.block.entity; | ||
|
||
import dev.hephaestus.glowcase.Glowcase; | ||
import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.network.listener.ClientPlayPacketListener; | ||
import net.minecraft.network.packet.Packet; | ||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3i; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class WireframeBlockEntity extends BlockEntity { | ||
public Vec3i offset = Vec3i.ZERO; | ||
public Vec3i scale = new Vec3i(1, 1, 1); | ||
public int color = 0xFFFFFF; | ||
|
||
public WireframeBlockEntity(BlockPos pos, BlockState state) { | ||
super(Glowcase.WIREFRAME_BLOCK_ENTITY.get(), pos, state); | ||
} | ||
|
||
@Override | ||
public void writeNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { | ||
super.writeNbt(tag, registryLookup); | ||
|
||
tag.putIntArray("offset", List.of(this.offset.getX(), this.offset.getY(), this.offset.getZ())); | ||
tag.putIntArray("scale", List.of(this.scale.getX(), this.scale.getY(), this.scale.getZ())); | ||
tag.putInt("color", this.color); | ||
} | ||
|
||
@Override | ||
public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { | ||
super.readNbt(tag, registryLookup); | ||
|
||
int[] offset = tag.getIntArray("offset"); | ||
int[] scale = tag.getIntArray("scale"); | ||
|
||
this.offset = new Vec3i(offset[0], offset[1], offset[2]); | ||
this.scale = new Vec3i(scale[0], scale[1], scale[2]); | ||
this.color = tag.getInt("color"); | ||
} | ||
|
||
@SuppressWarnings({"MethodCallSideOnly", "VariableUseSideOnly"}) | ||
@Override | ||
public void markRemoved() { | ||
if (world != null && world.isClient) { | ||
BakedBlockEntityRenderer.Manager.markForRebuild(getPos()); | ||
} | ||
super.markRemoved(); | ||
} | ||
|
||
// standard blockentity boilerplate | ||
|
||
public void dispatch() { | ||
if (world instanceof ServerWorld sworld) sworld.getChunkManager().markForUpdate(pos); | ||
} | ||
|
||
@Override | ||
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) { | ||
return createNbt(registryLookup); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Packet<ClientPlayPacketListener> toUpdatePacket() { | ||
return BlockEntityUpdateS2CPacket.create(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.