Skip to content

Commit ecc01f1

Browse files
committed
add slate canvas (mostly), some stuff with the great book, maybe #51 and #40, and gloop block
1 parent 02bc00e commit ecc01f1

30 files changed

+742
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.vscode/launch.json
3+
.vscode/settings.json
34
/TexturePSDs/
45
run/
56
build/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static void registerRenderers(){
123123
BlockEntityRendererRegistry.register(HexGloopBEs.CONJURED_REDSTONE_BE.get(), BERConjuredRedstone::new);
124124
BlockEntityRendererRegistry.register(HexGloopBEs.SLATE_CHEST_BE.get(), BERHexChest::new);
125125
RenderTypeRegistry.register(RenderLayer.getTranslucent(), HexGloopBlocks.CONJURED_REDSTONE_BLOCK.get(), HexGloopBlocks.HEXXED_GLASS_BLOCK.get(),
126-
HexGloopBlocks.ENLIGHTENMENT_BRIDGE_BLOCK.get(), HexGloopBlocks.ENLIGHTENMENT_GATE_BLOCK.get());
126+
HexGloopBlocks.ENLIGHTENMENT_BRIDGE_BLOCK.get(), HexGloopBlocks.ENLIGHTENMENT_GATE_BLOCK.get(), HexGloopBlocks.GLOOP_BLOCK.get());
127127
}
128128

129129
private static void registerColorProviders(){

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

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.minecraft.block.BlockState;
1515
import net.minecraft.block.MapColor;
1616
import net.minecraft.block.Material;
17+
import net.minecraft.block.SlimeBlock;
1718
import net.minecraft.item.BlockItem;
1819
import net.minecraft.item.Item;
1920
import net.minecraft.sound.BlockSoundGroup;
@@ -75,6 +76,9 @@ public class HexGloopBlocks {
7576
public static final RegistrySupplier<Block> CHARGED_AMETHYST_BLOCK = block("charged_amethyst_block",
7677
() -> new Block(AbstractBlock.Settings.of(Material.AMETHYST, MapColor.TERRACOTTA_PURPLE).requiresTool().strength(5.0f, 6.0f).sounds(BlockSoundGroup.AMETHYST_BLOCK)));
7778

79+
public static final RegistrySupplier<Block> GLOOP_BLOCK = block("gloop_block",
80+
() -> new SlimeBlock(AbstractBlock.Settings.of(Material.ORGANIC_PRODUCT, MapColor.BRIGHT_TEAL).requiresTool().strength(5.0f, 6.0f).nonOpaque().slipperiness(0.8F).sounds(BlockSoundGroup.SLIME)));
81+
7882
public static final RegistrySupplier<Block> THINKING_CARPET_BLOCK = block("thinking_carpet",
7983
() -> new BlockThinkingCarpet(AbstractBlock.Settings.of(Material.CARPET, MapColor.TERRACOTTA_PURPLE).strength(0.1f).sounds(BlockSoundGroup.WOOL)));
8084

common/src/main/java/com/samsthenerd/hexgloop/casting/HexGloopRegisterPatterns.java

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import com.samsthenerd.hexgloop.HexGloop;
1010
import com.samsthenerd.hexgloop.blocks.HexGloopBlocks;
11+
import com.samsthenerd.hexgloop.casting.canvas.OpGetBlockColor;
12+
import com.samsthenerd.hexgloop.casting.canvas.OpPutColor;
1113
import com.samsthenerd.hexgloop.casting.dimensions.OpIsInDimension;
1214
import com.samsthenerd.hexgloop.casting.gloopifact.OpReadGloopifact;
1315
import com.samsthenerd.hexgloop.casting.gloopifact.OpSyncRavenmindGloopifact;
@@ -209,6 +211,13 @@ public static void registerPatterns(){
209211
new Identifier(HexGloop.MOD_ID, "stonecut"),
210212
new OpStoneCut());
211213

214+
PatternRegistry.mapPattern(HexPattern.fromAngles("edeaeeeweee", HexDir.SOUTH_EAST),
215+
new Identifier(HexGloop.MOD_ID, "put_canvas_color"),
216+
new OpPutColor());
217+
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqeqwawqwa", HexDir.NORTH_WEST),
218+
new Identifier(HexGloop.MOD_ID, "get_block_color"),
219+
new OpGetBlockColor());
220+
212221
} catch (PatternRegistry.RegisterPatternException exn) {
213222
exn.printStackTrace();
214223
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.samsthenerd.hexgloop.casting.canvas;
2+
3+
import java.util.List;
4+
5+
import at.petrak.hexcasting.api.spell.ConstMediaAction;
6+
import at.petrak.hexcasting.api.spell.OperationResult;
7+
import at.petrak.hexcasting.api.spell.OperatorUtils;
8+
import at.petrak.hexcasting.api.spell.casting.CastingContext;
9+
import at.petrak.hexcasting.api.spell.casting.eval.SpellContinuation;
10+
import at.petrak.hexcasting.api.spell.iota.DoubleIota;
11+
import at.petrak.hexcasting.api.spell.iota.Iota;
12+
import at.petrak.hexcasting.api.spell.iota.Vec3Iota;
13+
import net.minecraft.block.BlockState;
14+
import net.minecraft.block.MapColor;
15+
import net.minecraft.block.MapColor.Brightness;
16+
import net.minecraft.text.Text;
17+
import net.minecraft.util.math.BlockPos;
18+
import net.minecraft.util.math.Vec3d;
19+
20+
public class OpGetBlockColor implements ConstMediaAction{
21+
22+
public OpGetBlockColor(){
23+
}
24+
25+
@Override
26+
public int getArgc(){ return 1; }
27+
28+
@Override
29+
public int getMediaCost(){
30+
return 0;
31+
}
32+
33+
@Override
34+
public boolean isGreat(){ return false;}
35+
36+
@Override
37+
public boolean getCausesBlindDiversion(){ return false;}
38+
39+
@Override
40+
public boolean getAlwaysProcessGreatSpell(){ return false;}
41+
42+
@Override
43+
public Text getDisplayName(){
44+
return DefaultImpls.getDisplayName(this);
45+
}
46+
47+
@Override
48+
public List<Iota> execute(List<? extends Iota> args, CastingContext context){
49+
Brightness brightness = Brightness.NORMAL;
50+
int argOffset = 0;
51+
if(args.get(0) instanceof DoubleIota doubleIota){
52+
double brightnessVal = doubleIota.getDouble();
53+
if(brightnessVal >= 0 && brightnessVal <= 3){
54+
brightness = Brightness.validateAndGet((int)brightnessVal);
55+
argOffset = 1;
56+
}
57+
}
58+
BlockPos pos = OperatorUtils.getBlockPos(args, argOffset, getArgc());
59+
BlockState state = context.getWorld().getBlockState(pos);
60+
MapColor mapColor = state.getMapColor(context.getWorld(), pos);
61+
int rgb = mapColor.getRenderColor(brightness);
62+
return List.of(new Vec3Iota(new Vec3d((rgb >>> 16) & 0xFF, (rgb >>> 8) & 0xFF, rgb & 0xFF)));
63+
}
64+
65+
@Override
66+
public OperationResult operate(SpellContinuation continuation, List<Iota> stack, Iota ravenmind, CastingContext castingContext){
67+
return ConstMediaAction.DefaultImpls.operate(this, continuation, stack, ravenmind, castingContext);
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.samsthenerd.hexgloop.casting.canvas;
2+
3+
public class OpGetColor {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.samsthenerd.hexgloop.casting.canvas;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.samsthenerd.hexgloop.HexGloop;
7+
import com.samsthenerd.hexgloop.items.HexGloopItems;
8+
import com.samsthenerd.hexgloop.items.ItemSlateCanvas;
9+
10+
import at.petrak.hexcasting.api.spell.Action;
11+
import at.petrak.hexcasting.api.spell.OperationResult;
12+
import at.petrak.hexcasting.api.spell.OperatorUtils;
13+
import at.petrak.hexcasting.api.spell.casting.CastingContext;
14+
import at.petrak.hexcasting.api.spell.casting.eval.SpellContinuation;
15+
import at.petrak.hexcasting.api.spell.casting.sideeffects.OperatorSideEffect;
16+
import at.petrak.hexcasting.api.spell.iota.Iota;
17+
import at.petrak.hexcasting.api.spell.iota.NullIota;
18+
import kotlin.collections.CollectionsKt;
19+
import net.minecraft.block.MapColor;
20+
import net.minecraft.block.MapColor.Brightness;
21+
import net.minecraft.item.FilledMapItem;
22+
import net.minecraft.item.ItemStack;
23+
import net.minecraft.item.map.MapState;
24+
import net.minecraft.text.Text;
25+
import net.minecraft.util.Pair;
26+
import net.minecraft.util.math.Vec3d;
27+
import net.minecraft.util.math.Vec3i;
28+
29+
public class OpPutColor implements Action{
30+
31+
public OpPutColor(){
32+
}
33+
34+
@Override
35+
public boolean isGreat(){ return false;}
36+
37+
@Override
38+
public boolean getCausesBlindDiversion(){ return false;}
39+
40+
@Override
41+
public boolean getAlwaysProcessGreatSpell(){ return false;}
42+
43+
@Override
44+
public Text getDisplayName(){
45+
return DefaultImpls.getDisplayName(this);
46+
}
47+
48+
@Override
49+
public OperationResult operate(SpellContinuation continuation, List<Iota> stack, Iota ravenmind, CastingContext context){
50+
// potentially get an entity first -- deal with that later
51+
ItemStack mapStack = context.getHeldItemToOperateOn(itemstack -> itemstack.isOf(HexGloopItems.SLATE_CANVAS_ITEM.get())).component1();
52+
53+
HexGloop.logPrint("args: " + stack.toString());
54+
55+
int brushsize = 1;
56+
try {
57+
brushsize = OperatorUtils.getIntBetween(List.of(stack.get(stack.size()-1)), 0, 1, 128, 1);
58+
stack.remove(stack.size()-1);
59+
} catch (Throwable mishap) {
60+
// do nothing
61+
HexGloop.logPrint("mishap: " + mishap);
62+
}
63+
64+
List<Iota> args = CollectionsKt.takeLast(stack, 3);
65+
66+
Integer x = null;
67+
if(!(args.get(0) instanceof NullIota)){
68+
x = OperatorUtils.getIntBetween(args, 0, 0, 127, 3);
69+
}
70+
Integer y = null;
71+
if(!(args.get(1) instanceof NullIota)){
72+
y = OperatorUtils.getIntBetween(args, 1, 0, 127, 3);
73+
}
74+
byte closestColor = MapColor.CLEAR.getRenderColorByte(Brightness.NORMAL);
75+
if(!(args.get(2) instanceof NullIota)){
76+
Vec3d colorVec = OperatorUtils.getVec3(args, 2, 3);
77+
closestColor = SlateCanvasUtils.getClosestMapColor(new Vec3i(colorVec.x, colorVec.y, colorVec.z), context.getCaster());
78+
}
79+
80+
for(int i = 0; i < 3; i++){
81+
stack.remove(stack.size()-1);
82+
}
83+
84+
Integer mapId = FilledMapItem.getMapId(mapStack);
85+
if(mapId == null){
86+
HexGloop.logPrint("creating a new map");
87+
Pair<MapState, Integer> newMapData = ItemSlateCanvas.createMapState(context.getWorld());
88+
mapId = newMapData.getRight();
89+
ItemSlateCanvas.setCanvasMapId(mapStack, mapId);
90+
}
91+
HexGloop.logPrint("map id: " + mapId);
92+
MapState mapState = FilledMapItem.getMapState(mapId, context.getWorld());
93+
if(x == null && y == null){ // paint whole thing
94+
for(int i = 0; i < 128; i++){
95+
for(int j = 0; j < 128; j++){
96+
mapState.setColor(i, j, closestColor);
97+
}
98+
}
99+
} else {
100+
int startX = 0, startY = 0;
101+
int endX = 128, endY = 128;
102+
103+
if(x != null){
104+
startX = (int)(x - Math.floor((brushsize-1)/2.0));
105+
endX = (int)(x + Math.ceil((brushsize+1)/2.0));
106+
}
107+
108+
if(y != null){
109+
startY = (int)(y - Math.floor((brushsize-1)/2.0));
110+
endY = (int)(y + Math.ceil((brushsize+1)/2.0));
111+
}
112+
113+
// clamp all the values down to actual sizes
114+
startX = Math.min(Math.max(0, startX), 128);
115+
startY = Math.min(Math.max(0, startY), 128);
116+
endX = Math.min(Math.max(0, endX), 128);
117+
endY = Math.min(Math.max(0, endY), 128);
118+
119+
for(int i = startX; i < endX; i++){
120+
for(int j = startY; j < endY; j++){
121+
mapState.setColor(i, j, closestColor);
122+
}
123+
}
124+
}
125+
return new OperationResult(continuation, stack, ravenmind, new ArrayList<OperatorSideEffect>());
126+
}
127+
128+
}

0 commit comments

Comments
 (0)