-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Want to discourage use of forge data for the texture as its difficult to sync Added syncing for the forge data approach, as you can see its difficult
- Loading branch information
1 parent
a79684a
commit 0bdd148
Showing
4 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/slimeknights/mantle/block/entity/DefaultRetexturedBlockEntity.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 slimeknights.mantle.block.entity; | ||
|
||
import lombok.Getter; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.client.model.data.IModelData; | ||
import net.minecraftforge.common.util.Lazy; | ||
import slimeknights.mantle.block.RetexturedBlock; | ||
import slimeknights.mantle.util.RetexturedHelper; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static slimeknights.mantle.util.RetexturedHelper.TAG_TEXTURE; | ||
|
||
/** | ||
* Standard implementation for {@link IRetexturedBlockEntity}, use alongside {@link RetexturedBlock} and {@link slimeknights.mantle.item.RetexturedBlockItem} | ||
*/ | ||
public class DefaultRetexturedBlockEntity extends MantleBlockEntity implements IRetexturedBlockEntity { | ||
private final Lazy<IModelData> data = Lazy.of(this::getRetexturedModelData); | ||
@Nonnull | ||
@Getter | ||
private Block texture = Blocks.AIR; | ||
public DefaultRetexturedBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { | ||
super(type, pos, state); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public IModelData getModelData() { | ||
return this.data.get(); | ||
} | ||
|
||
@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); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean shouldSyncOnUpdate() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void saveSynced(CompoundTag tags) { | ||
super.saveSynced(tags); | ||
if (texture != Blocks.AIR) { | ||
tags.putString(TAG_TEXTURE, getTextureName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void load(CompoundTag tags) { | ||
super.load(tags); | ||
if (tags.contains(TAG_TEXTURE, Tag.TAG_STRING)) { | ||
texture = RetexturedHelper.getBlock(tags.getString(TAG_TEXTURE)); | ||
RetexturedHelper.onTextureUpdated(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