mirror of
https://github.com/TeamMidnightDust/Decorative.git
synced 2025-12-15 12:35:10 +01:00
Colored bird bath water on Polymer
- Thanks to @Patbox for implementing the necessary changes in Polymer this fast!
This commit is contained in:
@@ -17,5 +17,5 @@ org.gradle.jvmargs=-Xmx2G
|
|||||||
fabric_version=0.100.7+1.21
|
fabric_version=0.100.7+1.21
|
||||||
midnightlib_version=1.5.7-fabric
|
midnightlib_version=1.5.7-fabric
|
||||||
patchouli_version=1.18.2-67-FABRIC
|
patchouli_version=1.18.2-67-FABRIC
|
||||||
polymer_version=0.9.7+1.21
|
polymer_version=0.9.8+1.21
|
||||||
factorytools_version=0.3.1+1.21
|
factorytools_version=0.3.1+1.21
|
||||||
|
|||||||
@@ -137,6 +137,6 @@ public class BirdBath extends AbstractCauldronBlock implements FactoryBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||||
return new ItemDisplayBirdBathModel(initialBlockState, pos, world);
|
return new ItemDisplayBirdBathModel(initialBlockState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import eu.pb4.factorytools.api.resourcepack.BaseItemProvider;
|
|||||||
import eu.pb4.factorytools.api.virtualentity.BlockModel;
|
import eu.pb4.factorytools.api.virtualentity.BlockModel;
|
||||||
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
|
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
|
||||||
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
|
import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment;
|
||||||
|
import eu.pb4.polymer.virtualentity.api.attachment.ChunkAttachment;
|
||||||
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
|
import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment;
|
||||||
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
|
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@@ -19,6 +20,7 @@ import net.minecraft.potion.Potions;
|
|||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,6 +31,7 @@ import static eu.midnightdust.motschen.decorative.DecorativeMain.id;
|
|||||||
public class ItemDisplayBirdBathModel extends BlockModel {
|
public class ItemDisplayBirdBathModel extends BlockModel {
|
||||||
private final ItemDisplayElement main;
|
private final ItemDisplayElement main;
|
||||||
private final ItemDisplayElement water;
|
private final ItemDisplayElement water;
|
||||||
|
private int waterColor = ColorUtil.convertRgbToArgb(4159204);
|
||||||
public static ItemStack STONE;
|
public static ItemStack STONE;
|
||||||
public static ItemStack WATER;
|
public static ItemStack WATER;
|
||||||
|
|
||||||
@@ -37,20 +40,16 @@ public class ItemDisplayBirdBathModel extends BlockModel {
|
|||||||
WATER = BaseItemProvider.requestModel(Items.POTION, id("block/polymer/bird_bath_water"));
|
WATER = BaseItemProvider.requestModel(Items.POTION, id("block/polymer/bird_bath_water"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplayBirdBathModel(BlockState state, BlockPos pos, ServerWorld world) {
|
public ItemDisplayBirdBathModel(BlockState state) {
|
||||||
this.main = ItemDisplayElementUtil.createSimple(STONE);
|
this.main = ItemDisplayElementUtil.createSimple(STONE);
|
||||||
this.main.setDisplaySize(1, 1);
|
this.main.setDisplaySize(1, 1);
|
||||||
this.main.setScale(new Vector3f(2));
|
this.main.setScale(new Vector3f(2));
|
||||||
this.main.setViewRange(0.75f * (DecorativeConfig.viewDistance / 100f));
|
this.main.setViewRange(0.75f * (DecorativeConfig.viewDistance / 100f));
|
||||||
this.addElement(this.main);
|
this.addElement(this.main);
|
||||||
|
|
||||||
// TODO: Get actual biome color when it's implemented in Polymer
|
this.water = ItemDisplayElementUtil.createSimple();
|
||||||
// int baseColor = ColorUtil.getWaterColor(world, pos);
|
|
||||||
int color = ColorUtil.convertRgbToArgb(4159204);
|
|
||||||
WATER.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Optional.of(Potions.WATER), Optional.of(color), List.of())).build());
|
|
||||||
this.water = ItemDisplayElementUtil.createSimple(WATER);
|
|
||||||
this.water.setDisplaySize(1, 1);
|
this.water.setDisplaySize(1, 1);
|
||||||
this.water.setScale(new Vector3f(2));
|
this.water.setScale(new Vector3f(state.get(BirdBath.LEVEL) >= 2 ? 1.9f : 1.65f));
|
||||||
this.water.setOffset(new Vec3d(0d, -0.025 * (3-(state.get(BirdBath.LEVEL))), 0d));
|
this.water.setOffset(new Vec3d(0d, -0.025 * (3-(state.get(BirdBath.LEVEL))), 0d));
|
||||||
this.water.setViewRange(state.get(BirdBath.LEVEL) != 0 ? (0.75f * (DecorativeConfig.viewDistance / 100f)) : 0);
|
this.water.setViewRange(state.get(BirdBath.LEVEL) != 0 ? (0.75f * (DecorativeConfig.viewDistance / 100f)) : 0);
|
||||||
this.addElement(this.water);
|
this.addElement(this.water);
|
||||||
@@ -61,10 +60,24 @@ public class ItemDisplayBirdBathModel extends BlockModel {
|
|||||||
if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) {
|
if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) {
|
||||||
var state = this.blockState();
|
var state = this.blockState();
|
||||||
this.water.setViewRange(state.get(BirdBath.LEVEL) != 0 ? (0.75f * (DecorativeConfig.viewDistance / 100f)) : 0);
|
this.water.setViewRange(state.get(BirdBath.LEVEL) != 0 ? (0.75f * (DecorativeConfig.viewDistance / 100f)) : 0);
|
||||||
|
this.water.setScale(new Vector3f(state.get(BirdBath.LEVEL) >= 2 ? 1.9f : 1.65f));
|
||||||
this.water.setOffset(new Vec3d(0d, -0.025 * (3-(state.get(BirdBath.LEVEL))), 0d));
|
this.water.setOffset(new Vec3d(0d, -0.025 * (3-(state.get(BirdBath.LEVEL))), 0d));
|
||||||
|
|
||||||
this.tick();
|
this.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
protected void onAttachmentSet(HolderAttachment attachment, @Nullable HolderAttachment oldAttachment) {
|
||||||
|
if (attachment instanceof ChunkAttachment chunkAttachment) {
|
||||||
|
this.waterColor = ColorUtil.convertRgbToArgb(ColorUtil.getWaterColor(chunkAttachment.getChunk(), blockPos()));
|
||||||
|
this.water.setItem(getColoredWater());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private ItemStack getColoredWater() {
|
||||||
|
var colWater = WATER.copy();
|
||||||
|
colWater.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.POTION_CONTENTS,
|
||||||
|
new PotionContentsComponent(Optional.of(Potions.WATER), Optional.of(this.waterColor), List.of())).build());
|
||||||
|
return colWater;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package eu.midnightdust.motschen.decorative.util;
|
package eu.midnightdust.motschen.decorative.util;
|
||||||
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.biome.source.BiomeCoords;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -14,8 +15,10 @@ public class ColorUtil {
|
|||||||
|
|
||||||
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||||
}
|
}
|
||||||
public static int getWaterColor(ServerWorld world, BlockPos pos) {
|
public static int getWaterColor(Chunk chunk, BlockPos pos) {
|
||||||
var biome = world.getBiome(pos);
|
var biome = chunk.getBiomeForNoiseGen(BiomeCoords.fromBlock(pos.getX()),
|
||||||
|
BiomeCoords.fromBlock(pos.getY()),
|
||||||
|
BiomeCoords.fromBlock(pos.getZ()));
|
||||||
return biome == null ? 4159204 : biome.value().getWaterColor();
|
return biome == null ? 4159204 : biome.value().getWaterColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user