Skip to content

Commit

Permalink
Update Mantle and fix a bug where shelves and bushes do not show text…
Browse files Browse the repository at this point in the history
…ure on world load

Mantle update also fixes a bug with cauldrons rendering black
  • Loading branch information
KnightMiner committed Nov 6, 2022
1 parent 9ba9f44 commit 0b55c9e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -11,6 +11,6 @@ loader_range=[33.0,)

# Dependencies
parchment_version=2022.09.04
mantle_version=1.9.29
mantle_range=[1.9.29,)
mantle_version=1.9.31
mantle_range=[1.9.31,)
jei_version=9.7.2.266
Expand Up @@ -3,12 +3,12 @@
import knightminer.inspirations.building.InspirationsBuilding;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import slimeknights.mantle.block.entity.RetexturedBlockEntity;
import slimeknights.mantle.block.entity.DefaultRetexturedBlockEntity;

/**
* Simply a wrapper around the base one to add in the custom type
*/
public class EnlightenedBushBlockEntity extends RetexturedBlockEntity {
public class EnlightenedBushBlockEntity extends DefaultRetexturedBlockEntity {
public EnlightenedBushBlockEntity(BlockPos pos, BlockState state) {
super(InspirationsBuilding.enlightenedBushTileEntity, pos, state);
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.client.model.data.ModelProperty;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
Expand All @@ -38,6 +39,9 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

import static slimeknights.mantle.util.RetexturedHelper.TAG_TEXTURE;

public class ShelfBlockEntity extends NameableBlockEntity implements IRetexturedBlockEntity {
public static final ModelProperty<Integer> BOOKS = new ModelProperty<>();
Expand All @@ -48,9 +52,14 @@ public class ShelfBlockEntity extends NameableBlockEntity implements IRetextured
*/
private float enchantBonus = Float.NaN;

// inventory
private final ShelfInventory inventory = new ShelfInventory(this);
private final LazyOptional<IItemHandler> itemCapability = LazyOptional.of(() -> inventory);
private final IModelData data = new ModelDataMap.Builder().withProperty(BOOKS).withProperty(RetexturedHelper.BLOCK_PROPERTY).build();

// display
private final Lazy<IModelData> data = Lazy.of(this::getRetexturedModelData);
private Block texture = Blocks.AIR;

public ShelfBlockEntity(BlockPos pos, BlockState state) {
super(InspirationsBuilding.shelfTileEntity, pos, state, TITLE);
}
Expand Down Expand Up @@ -159,13 +168,24 @@ public boolean interact(Player player, InteractionHand hand, Vec3 click) {
public void onSlotChanged(int slot, ItemStack oldStack, ItemStack newStack) {
// slot update
Level world = getLevel();
if (world != null && !world.isClientSide) {
InspirationsNetwork.sendToClients(world, this.worldPosition, new InventorySlotSyncPacket(newStack, slot, worldPosition));
}
if (world != null) {
// update for rendering
if (world.isClientSide) {
ModelDataManager.requestModelDataRefresh(this);
if (!world.isClientSide) {
InspirationsNetwork.sendToClients(world, this.worldPosition, new InventorySlotSyncPacket(newStack, slot, worldPosition));
}
else {
// update displayed book
IModelData data = this.data.get();
int oldBooks = Objects.requireNonNullElse(data.getData(BOOKS), 0);
int books;
if (InspirationsRegistry.isBook(newStack)) {
books = oldBooks | 1 << slot;
} else {
books = oldBooks & ~(1 << slot);
}
if (books != oldBooks) {
data.setData(BOOKS, books);
ModelDataManager.requestModelDataRefresh(this);
}
}

// if we have redstone books and either the old stack xor the new one is a book, update
Expand Down Expand Up @@ -252,12 +272,40 @@ public float getEnchantPower() {
return enchantBonus;
}


/*
* Rendering
*/

@Override
public Block getTexture() {
return texture;
}

@Override
public String getTextureName() {
return RetexturedHelper.getTextureName(texture);
}

@Override
public void updateTexture(String name) {
Block oldTexture = texture;
texture = RetexturedHelper.getBlock(name);
if (oldTexture != texture) {
setChangedFast();
RetexturedHelper.onTextureUpdated(this);
}
}

@Nonnull
@Override
public IModelData getModelData() {
return this.data.get();
}

@Override
public IModelData getRetexturedModelData() {
IModelData data = new ModelDataMap.Builder().withProperty(BOOKS).withProperty(RetexturedHelper.BLOCK_PROPERTY).build();
// pack books into integer
int books = 0;
for (int i = 0; i < ShelfInventory.MAX_ITEMS; i++) {
Expand Down Expand Up @@ -293,6 +341,9 @@ protected boolean shouldSyncOnUpdate() {
public void saveSynced(CompoundTag tags) {
super.saveSynced(tags);
tags.put(TAG_ITEMS, inventory.serializeNBT());
if (texture != Blocks.AIR) {
tags.putString(TAG_TEXTURE, getTextureName());
}
}

@Override
Expand All @@ -306,5 +357,9 @@ public void load(CompoundTag tags) {
level.sendBlockUpdated(worldPosition, state, state, 0);
}
}
if (tags.contains(TAG_TEXTURE, Tag.TAG_STRING)) {
texture = RetexturedHelper.getBlock(tags.getString(TAG_TEXTURE));
RetexturedHelper.onTextureUpdated(this);
}
}
}

0 comments on commit 0b55c9e

Please sign in to comment.