Skip to content

Commit

Permalink
some small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Dec 23, 2024
1 parent 2a4d32e commit a559365
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 17 deletions.
9 changes: 4 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Additions

- Fancy Crafter

# Fixes

- Placed Clipboards are no longer visible through walls
- Fixed clipboard flickering at long distances
- Fixed sword pedestal color changing when receiving a block update
- Fixed sword pedestal breaking particles
- Fixed tape measure showing incorrect distances
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.configuration-cache=true

mod.group=com.github.minecraftschurlimods
mod.id=bibliocraft
mod.version=1.2.0
mod.version=1.2.1
mod.name=Bibliocraft Legacy
mod.vendor=MinecraftschurliMods
mod.authors=IchHabeHunger54, Minecraftschurli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static void registerRenderers(EntityRenderersEvent.RegisterRenderers eve

@SubscribeEvent
private static void registerColorHandlersBlock(RegisterColorHandlersEvent.Block event) {
event.register((state, level, pos, tintIndex) -> tintIndex == 0 && Objects.requireNonNull(level).getBlockEntity(Objects.requireNonNull(pos)) instanceof SwordPedestalBlockEntity spbe ? spbe.getColor() : -1, BCBlocks.SWORD_PEDESTAL.get());
event.register((state, level, pos, tintIndex) -> tintIndex == 0 && Objects.requireNonNull(level).getBlockEntity(Objects.requireNonNull(pos)) instanceof SwordPedestalBlockEntity spbe ? spbe.getColor().rgb() : -1, BCBlocks.SWORD_PEDESTAL.get());
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void render(ClipboardBlockEntity blockEntity, float partialTick, PoseStac
ClientUtil.setupCenteredBER(stack, blockEntity);
stack.mulPose(Axis.XP.rotationDegrees(180));
stack.translate(-0.25, -0.25, 0.4375);
stack.translate(0, 0, -0.00001);
stack.translate(0, 0, -1 / 1024d);
float scale = 1 / 256f;
stack.scale(scale, scale, 0);
ClipboardReadOnlyRenderer.render(stack, buffer, blockEntity.getContent(), 128, 148);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@

import com.github.minecraftschurlimods.bibliocraft.init.BCBlockEntities;
import com.github.minecraftschurlimods.bibliocraft.init.BCTags;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.level.block.state.BlockState;

public class SwordPedestalBlockEntity extends BCBlockEntity {
private static final String COLOR_KEY = "color";
private DyedItemColor color = SwordPedestalBlock.DEFAULT_COLOR;

public SwordPedestalBlockEntity(BlockPos pos, BlockState state) {
super(BCBlockEntities.SWORD_PEDESTAL.get(), 1, pos, state);
}

/**
* @return The color of this sword pedestal.
*/
public int getColor() {
return components().getOrDefault(DataComponents.DYED_COLOR, SwordPedestalBlock.DEFAULT_COLOR).rgb();
public DyedItemColor getColor() {
return color;
}

public void setColor(DyedItemColor color) {
this.color = color;
setChanged();
}

@Override
Expand All @@ -29,4 +39,56 @@ public boolean canPlaceItem(int slot, ItemStack stack) {
public int getMaxStackSize() {
return 1;
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains(COLOR_KEY)) {
setColor(BCUtil.decodeNbt(DyedItemColor.CODEC, tag.get(COLOR_KEY)));
}
}

@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);
tag.put(COLOR_KEY, BCUtil.encodeNbt(DyedItemColor.CODEC, getColor()));
}

@Override
protected void applyImplicitComponents(DataComponentInput componentInput) {
super.applyImplicitComponents(componentInput);
setColor(componentInput.getOrDefault(DataComponents.DYED_COLOR, SwordPedestalBlock.DEFAULT_COLOR));
}

@Override
protected void collectImplicitComponents(DataComponentMap.Builder components) {
super.collectImplicitComponents(components);
if (!color.equals(SwordPedestalBlock.DEFAULT_COLOR)) {
components.set(DataComponents.DYED_COLOR, color);
}
}

@SuppressWarnings("deprecation")
@Override
public void removeComponentsFromTag(CompoundTag tag) {
super.removeComponentsFromTag(tag);
tag.remove(COLOR_KEY);
}

@Override
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
CompoundTag tag = super.getUpdateTag(registries);
if (!color.equals(SwordPedestalBlock.DEFAULT_COLOR)) {
tag.put(COLOR_KEY, BCUtil.encodeNbt(DyedItemColor.CODEC, getColor()));
}
return tag;
}

@Override
public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider lookupProvider) {
super.handleUpdateTag(tag, lookupProvider);
if (tag.contains(COLOR_KEY)) {
setColor(BCUtil.decodeNbt(DyedItemColor.CODEC, tag.get(COLOR_KEY)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public InteractionResult useOn(UseOnContext context) {
BlockPos pos = context.getClickedPos();
if (stack.has(BCDataComponents.STORED_POSITION)) {
BlockPos distance = context.getClickedPos().subtract(stack.getOrDefault(BCDataComponents.STORED_POSITION, StoredPosition.DEFAULT).position());
player.displayClientMessage(Component.translatable(Translations.TAPE_MEASURE_DISTANCE, distance.distSqr(BlockPos.ZERO), Math.abs(distance.getX()), Math.abs(distance.getY()), Math.abs(distance.getZ())), true);
player.displayClientMessage(Component.translatable(Translations.TAPE_MEASURE_DISTANCE, distance.distManhattan(BlockPos.ZERO), Math.abs(distance.getX()), Math.abs(distance.getY()), Math.abs(distance.getZ())), true);
stack.remove(BCDataComponents.STORED_POSITION);
} else {
stack.set(BCDataComponents.STORED_POSITION, new StoredPosition(pos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void clearContent() {
}

@Override
public void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
lockKey = LockCode.fromTag(tag);
if (tag.contains(ITEMS_TAG)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": "bibliocraft:block/sword_pedestal_base",
"1": "bibliocraft:block/sword_pedestal_side",
"2": "bibliocraft:block/sword_pedestal_overlay",
"particle": "bibliocraft:block/sword_pedestal/base"
"particle": "bibliocraft:block/sword_pedestal_base"
},
"elements": [
{
Expand Down
2 changes: 1 addition & 1 deletion summary.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add Fancy Crafter and some fixes
Some small bug fixes

0 comments on commit a559365

Please sign in to comment.