Skip to content

Commit d236077

Browse files
committed
some more work on making dials pretty, also gave flaying table a scrying overlay, guess it didn't have one before oops
1 parent 12b82f4 commit d236077

File tree

12 files changed

+180
-5
lines changed

12 files changed

+180
-5
lines changed

common/src/main/java/com/samsthenerd/hexgloop/HexGloopClient.java

+39
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.mojang.datafixers.util.Pair;
99
import com.samsthenerd.hexgloop.blockentities.BERConjuredRedstone;
1010
import com.samsthenerd.hexgloop.blockentities.BERHexChest;
11+
import com.samsthenerd.hexgloop.blockentities.BlockEntityDial;
1112
import com.samsthenerd.hexgloop.blockentities.BlockEntityGloopEnergizer;
1213
import com.samsthenerd.hexgloop.blockentities.BlockEntityPedestal;
1314
import com.samsthenerd.hexgloop.blockentities.HexGloopBEs;
@@ -205,6 +206,31 @@ private static void registerColorProviders(){
205206
}
206207
return 0xFF_FFFFFF;
207208
}, HexGloopItems.ESSENCE_STONE_ITEM);
209+
210+
int emptyColor = 0x382f40;
211+
212+
ColorHandlerRegistry.registerBlockColors((state, world, pos, tintIndex) -> {
213+
if(!(world.getBlockEntity(pos) instanceof BlockEntityDial dialBE)){
214+
return emptyColor;
215+
}
216+
ItemStack stack = dialBE.getInnerMultiFocus().copy();
217+
if(stack.isEmpty()){
218+
return emptyColor;
219+
}
220+
if(tintIndex == 0){
221+
NbtCompound tag = HexGloopItems.MULTI_FOCUS_ITEM.get().readIotaTag(stack);
222+
if(tag == null){
223+
return emptyColor;
224+
}
225+
return HexIotaTypes.getColor(tag);
226+
}
227+
int selIndex = tintIndex + (tintIndex >= dialBE.getSelection() ? 1 : 0);
228+
NbtCompound tag = HexGloopItems.MULTI_FOCUS_ITEM.get().readSlotIotaTag(stack, selIndex);
229+
if(tag == null){
230+
return emptyColor;
231+
}
232+
return HexIotaTypes.getColor(tag);
233+
}, HexGloopBlocks.IOTIC_DIAL_BLOCK);
208234
}
209235

210236
public static int tintsFromColorizer(FrozenColorizer colorizer, int tintIndex, int sections){
@@ -404,5 +430,18 @@ private static void registerScryingDisplayers(){
404430

405431
ScryingLensOverlayRegistry.addDisplayer(HexGloopBlocks.PEDESTAL_BLOCK.get(), HexGloopClient::pedestalDisplay);
406432
ScryingLensOverlayRegistry.addDisplayer(HexGloopBlocks.MIRROR_PEDESTAL_BLOCK.get(), HexGloopClient::pedestalDisplay);
433+
ScryingLensOverlayRegistry.addDisplayer(HexGloopBlocks.MIND_PEDESTAL_BLOCK.get(), HexGloopClient::pedestalDisplay);
434+
435+
ScryingLensOverlayRegistry.addDisplayer(HexGloopBlocks.IOTIC_DIAL_BLOCK.get(),
436+
(lines, state, pos, observer, world, direction) -> {
437+
if(world.getBlockEntity(pos) instanceof BlockEntityDial dialBE){
438+
ItemStack stack = dialBE.getInnerMultiFocus();
439+
if(stack.isEmpty()) return;
440+
NbtCompound tag = HexGloopItems.MULTI_FOCUS_ITEM.get().readIotaTag(stack);
441+
if(tag == null) return;
442+
Text iotaDesc = HexIotaTypes.getDisplay(tag);
443+
lines.add(new Pair<>(stack, iotaDesc));
444+
}
445+
});
407446
}
408447
}

common/src/main/java/com/samsthenerd/hexgloop/blockentities/BlockEntityDial.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.samsthenerd.hexgloop.blockentities;
22

3+
import javax.annotation.Nullable;
4+
35
import com.samsthenerd.hexgloop.HexGloop;
46
import com.samsthenerd.hexgloop.blocks.BlockIoticDial;
57
import com.samsthenerd.hexgloop.blocks.iotic.IIoticProvider;
8+
import com.samsthenerd.hexgloop.items.ItemMultiFocus;
69

710
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
811
import at.petrak.hexcasting.common.items.ItemSpellbook;
@@ -11,7 +14,12 @@
1114
import net.minecraft.block.entity.BlockEntity;
1215
import net.minecraft.item.ItemStack;
1316
import net.minecraft.nbt.NbtCompound;
17+
import net.minecraft.network.Packet;
18+
import net.minecraft.network.listener.ClientPlayPacketListener;
19+
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
20+
import net.minecraft.server.world.ServerWorld;
1421
import net.minecraft.util.math.BlockPos;
22+
import net.minecraft.util.math.MathHelper;
1523
import net.minecraft.world.World;
1624

1725
public class BlockEntityDial extends BlockEntity implements IIoticProvider {
@@ -40,12 +48,19 @@ public void setInnerMultiFocus(ItemStack innerMultiFocus) {
4048
}
4149

4250
public void setSelection(int selection){
51+
selection = MathHelper.clamp(selection, 0, 6);
4352
BlockState old = world.getBlockState(pos);
4453
world.setBlockState(pos, old.with(BlockIoticDial.SELECTED, selection));
45-
// TODO: update the inner multi focus too
54+
if(selection != 0){
55+
ItemMultiFocus.setPageIdx(innerMultiFocus, selection);
56+
}
4657
markDirty();
4758
}
4859

60+
public int getSelection(){
61+
return world.getBlockState(pos).get(BlockIoticDial.SELECTED);
62+
}
63+
4964
// TODO: wrap this so we can get a hook when the iota is changed
5065
public ADIotaHolder getIotaHolder(World world, BlockPos pos){
5166
return IXplatAbstractions.INSTANCE.findDataHolder(innerMultiFocus);
@@ -60,4 +75,25 @@ protected void writeNbt(NbtCompound nbt) {
6075
super.writeNbt(nbt);
6176
nbt.put("innerMultiFocus", innerMultiFocus.writeNbt(new NbtCompound()));
6277
}
78+
79+
@Override
80+
public void markDirty() {
81+
if (world instanceof ServerWorld sWorld) {
82+
sWorld.getChunkManager().markForUpdate(pos);
83+
}
84+
super.markDirty();
85+
}
86+
87+
@Override
88+
public NbtCompound toInitialChunkDataNbt() {
89+
NbtCompound tag = new NbtCompound();
90+
this.writeNbt(tag);
91+
return tag;
92+
}
93+
94+
@Override
95+
@Nullable
96+
public Packet<ClientPlayPacketListener> toUpdatePacket() {
97+
return BlockEntityUpdateS2CPacket.create(this);
98+
}
6399
}

common/src/main/java/com/samsthenerd/hexgloop/blocks/BlockIoticDial.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public BlockRenderType getRenderType( @Nonnull BlockState state )
102102

103103
static {
104104
faceCalcs.put(Direction.Axis.X, (mirrored, pos) -> mirrored ? new Pair<>(pos.z, pos.y) : new Pair<>(1-pos.z, pos.y));
105-
faceCalcs.put(Direction.Axis.Y, (mirrored, pos) -> mirrored ? new Pair<>(pos.x, pos.z) : new Pair<>(1-pos.x, pos.z));
105+
faceCalcs.put(Direction.Axis.Y, (mirrored, pos) -> mirrored ? new Pair<>(pos.x, pos.z) : new Pair<>(pos.x, 1-pos.z));
106106
faceCalcs.put(Direction.Axis.Z, (mirrored, pos) -> mirrored ? new Pair<>(1-pos.x, pos.y) : new Pair<>(pos.x, pos.y));
107107
};
108108

@@ -119,6 +119,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
119119
dialBE.setInnerMultiFocus(ItemStack.EMPTY);
120120
return ActionResult.SUCCESS;
121121
}
122+
if(dialBE.getInnerMultiFocus().isEmpty()) return ActionResult.FAIL;
122123
Direction face = hit.getSide();
123124
Vec3d nPos = hit.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
124125
Pair<Double, Double> coords = faceCalcs.get(face.getAxis()).calc(face.getDirection() == Direction.AxisDirection.NEGATIVE, nPos);

common/src/main/java/com/samsthenerd/hexgloop/items/ItemMultiFocus.java

+11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ public NbtCompound readSlotIotaTag(ItemStack stack, int index){
105105
}
106106
}
107107

108+
public static int setPageIdx(ItemStack stack, int indexRaw){
109+
int originalIdx = ItemSpellbook.getPage(stack, 0);
110+
int index = MathHelper.clamp(indexRaw, 1, MAX_FOCI_SLOTS);
111+
if(originalIdx == 0){ return 0; };
112+
for(int i = 0; i < Math.abs(index - originalIdx); i++){
113+
boolean increase = index > originalIdx;
114+
rotatePageIdx(stack, increase);
115+
}
116+
return index;
117+
}
118+
108119
public static int rotatePageIdx(ItemStack stack, boolean increase) {
109120
int idx = ItemSpellbook.getPage(stack, 0);
110121
if (idx != 0) {

common/src/main/resources/assets/hexgloop/lang/en_us.json

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"block.hexgloop.enlightenment_bridge": "Caster's Bridge",
8787
"block.hexgloop.thinking_carpet": "Caster's Carpet",
8888
"block.hexgloop.conjured_redstone": "Conjured Redstone",
89+
"block.hexgloop.iotic_dial": "Iotic Dial",
8990

9091
"key.hexgloop.open_iota_wheel": "Open Iota Wheel",
9192
"key.hexgloop.casting_ring": "Use Casting Ring",

common/src/main/resources/assets/hexgloop/models/block/iotic_dial/empty.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"parent": "block/cube_bottom_top",
33
"textures":{
4-
"bottom": "minecraft:block/gold_block",
4+
"bottom": "hexgloop:block/iotic_dial/back",
55
"top": "hexgloop:block/iotic_dial/top_base",
66
"side": "hexgloop:block/iotic_dial/side"
77
},

common/src/main/resources/assets/hexgloop/models/block/iotic_dial/template.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"parent": "block/cube_bottom_top",
33
"textures":{
4-
"bottom": "minecraft:block/gold_block",
4+
"bottom": "hexgloop:block/iotic_dial/back",
5+
"bottomoverlay": "hexgloop:block/iotic_dial/back_glow",
56
"top": "hexgloop:block/iotic_dial/top_base",
67
"side": "hexgloop:block/iotic_dial/side",
78
"sideoverlay": "hexgloop:block/iotic_dial/side_glow"
@@ -20,9 +21,10 @@
2021
}
2122
},
2223
{
23-
"from": [ -0.01, 0, -0.01 ],
24+
"from": [ -0.01, -0.01, -0.01 ],
2425
"to": [ 16.01, 5, 16.01 ],
2526
"faces": {
27+
"down": { "texture": "#bottomoverlay", "cullface": "down", "tintindex": 0 },
2628
"north": { "texture": "#sideoverlay", "uv": [ 0, 11, 16, 16 ], "cullface": "north" , "tintindex": 0},
2729
"south": { "texture": "#sideoverlay", "uv": [ 0, 11, 16, 16 ], "cullface": "south" , "tintindex": 0},
2830
"west": { "texture": "#sideoverlay", "uv": [ 0, 11, 16, 16 ], "cullface": "west" , "tintindex": 0},
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.samsthenerd.hexgloop.mixins;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.Shadow;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.Inject;
7+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
8+
9+
import com.samsthenerd.hexgloop.blocks.BlockIoticDial;
10+
11+
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
12+
import me.jellysquid.mods.sodium.client.model.quad.blender.ColorSampler;
13+
import me.jellysquid.mods.sodium.client.model.quad.blender.LinearColorBlender;
14+
import me.jellysquid.mods.sodium.client.util.color.ColorARGB;
15+
import net.minecraft.block.Block;
16+
import net.minecraft.block.BlockState;
17+
import net.minecraft.util.math.BlockPos;
18+
import net.minecraft.world.BlockRenderView;
19+
20+
@Mixin(LinearColorBlender.class)
21+
public abstract class MixinSodiumBiomeBlendsNumberOneHater {
22+
@Shadow(remap = false)
23+
protected abstract <T> int getBlockColor(BlockRenderView world, T state, ColorSampler<T> sampler, int x, int y, int z, int colorIdx);
24+
25+
@Inject(method = "getVertexColor", at = @At("HEAD"), cancellable = true, remap = false)
26+
private <T> void onGetVertexColor(BlockRenderView world, BlockPos origin, ModelQuadView quad, ColorSampler<T> sampler, T state, int vertexIdx, CallbackInfoReturnable<Integer> info) {
27+
// The concept is from https://github.com/CaffeineMC/sodium-fabric/commit/634b11ed989482b9aab59ba45acc92ba31b97648
28+
// while the implementation is slightly based on #1331 by @devpelux: https://github.com/CaffeineMC/sodium-fabric/pull/1331
29+
if (state instanceof BlockState blockState) {
30+
Block block = blockState.getBlock();
31+
if (block instanceof BlockIoticDial) {
32+
int color = getBlockColor(world, state, sampler, origin.getX(), origin.getY(), origin.getZ(), quad.getColorIndex());
33+
info.setReturnValue(ColorARGB.toABGR(color));
34+
}
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.samsthenerd.hexgloop.mixins;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
import org.objectweb.asm.tree.ClassNode;
7+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
8+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
9+
10+
import net.fabricmc.loader.api.FabricLoader;
11+
12+
public class MixinSodiumPlugin implements IMixinConfigPlugin{
13+
@Override
14+
public void onLoad(String mixinPackage) {
15+
}
16+
17+
@Override
18+
public String getRefMapperConfig() {
19+
return null;
20+
}
21+
22+
@Override
23+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
24+
if(mixinClassName == "com.samsthenerd.duckyperiphs.mixin.SodiumBiomeBlendMixin.class"){
25+
return FabricLoader.getInstance().isModLoaded("sodium");
26+
}
27+
return true;
28+
}
29+
30+
@Override
31+
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
32+
}
33+
34+
@Override
35+
public List<String> getMixins() {
36+
return null;
37+
}
38+
39+
@Override
40+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
41+
42+
}
43+
44+
@Override
45+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
46+
}
47+
}

fabric/src/main/resources/hexgloop-fabric.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"mirroritems.MixinMaintainUsingCorrectItemFabric"
88
],
99
"client": [
10+
"MixinSodiumBiomeBlendsNumberOneHater"
1011
],
1112
"injectors": {
1213
"defaultRequire": 1

0 commit comments

Comments
 (0)