Skip to content

Commit 12b82f4

Browse files
committed
added some dial functionality and textures
1 parent 90dd455 commit 12b82f4

32 files changed

+445
-35
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ private static void registerRenderers(){
125125
BlockEntityRendererRegistry.register(HexGloopBEs.SLATE_CHEST_BE.get(), BERHexChest::new);
126126
RenderTypeRegistry.register(RenderLayer.getTranslucent(), HexGloopBlocks.CONJURED_REDSTONE_BLOCK.get(), HexGloopBlocks.HEXXED_GLASS_BLOCK.get(),
127127
HexGloopBlocks.ENLIGHTENMENT_BRIDGE_BLOCK.get(), HexGloopBlocks.ENLIGHTENMENT_GATE_BLOCK.get(), HexGloopBlocks.GLOOP_BLOCK.get());
128+
129+
RenderTypeRegistry.register(RenderLayer.getCutout(), HexGloopBlocks.IOTIC_DIAL_BLOCK.get());
128130
}
129131

130132
private static void registerColorProviders(){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.samsthenerd.hexgloop.blockentities;
2+
3+
import com.samsthenerd.hexgloop.HexGloop;
4+
import com.samsthenerd.hexgloop.blocks.BlockIoticDial;
5+
import com.samsthenerd.hexgloop.blocks.iotic.IIoticProvider;
6+
7+
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
8+
import at.petrak.hexcasting.common.items.ItemSpellbook;
9+
import at.petrak.hexcasting.xplat.IXplatAbstractions;
10+
import net.minecraft.block.BlockState;
11+
import net.minecraft.block.entity.BlockEntity;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.nbt.NbtCompound;
14+
import net.minecraft.util.math.BlockPos;
15+
import net.minecraft.world.World;
16+
17+
public class BlockEntityDial extends BlockEntity implements IIoticProvider {
18+
19+
private ItemStack innerMultiFocus = ItemStack.EMPTY;
20+
21+
public BlockEntityDial(BlockPos pos, BlockState state) {
22+
super(HexGloopBEs.DIAL_BE.get(), pos, state);
23+
}
24+
25+
public ItemStack getInnerMultiFocus() {
26+
return innerMultiFocus;
27+
}
28+
29+
// so that we can handle changing the blockstate
30+
public void setInnerMultiFocus(ItemStack innerMultiFocus) {
31+
this.innerMultiFocus = innerMultiFocus;
32+
BlockState old = world.getBlockState(pos);
33+
int sel = 0;
34+
if(!innerMultiFocus.isEmpty()){
35+
sel = ItemSpellbook.getPage(innerMultiFocus, 1);
36+
}
37+
world.setBlockState(pos, old.with(BlockIoticDial.SELECTED, sel));
38+
HexGloop.logPrint("new inner multi focus !");
39+
markDirty();
40+
}
41+
42+
public void setSelection(int selection){
43+
BlockState old = world.getBlockState(pos);
44+
world.setBlockState(pos, old.with(BlockIoticDial.SELECTED, selection));
45+
// TODO: update the inner multi focus too
46+
markDirty();
47+
}
48+
49+
// TODO: wrap this so we can get a hook when the iota is changed
50+
public ADIotaHolder getIotaHolder(World world, BlockPos pos){
51+
return IXplatAbstractions.INSTANCE.findDataHolder(innerMultiFocus);
52+
}
53+
54+
public void readNbt(NbtCompound nbt) {
55+
super.readNbt(nbt);
56+
innerMultiFocus = ItemStack.fromNbt(nbt.getCompound("innerMultiFocus"));
57+
}
58+
59+
protected void writeNbt(NbtCompound nbt) {
60+
super.writeNbt(nbt);
61+
nbt.put("innerMultiFocus", innerMultiFocus.writeNbt(new NbtCompound()));
62+
}
63+
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.samsthenerd.hexgloop.blocks.BlockPedestal;
1111
import com.samsthenerd.hexgloop.blocks.IDynamicFlayTarget;
12+
import com.samsthenerd.hexgloop.blocks.iotic.IIoticProvider;
1213
import com.samsthenerd.hexgloop.items.IMindTargetItem;
1314
import com.samsthenerd.hexgloop.misc.HexGloopTags;
1415
import com.samsthenerd.hexgloop.misc.INoMoving;
@@ -46,7 +47,7 @@
4647
import net.minecraft.world.World;
4748

4849
// switching it to sided so that it can be used by modded chutes and whatnot hopefully ?
49-
public class BlockEntityPedestal extends BlockEntity implements Inventory, IReallyHateForgeWhyWouldAnInventoryInterfaceNotBeAnInterfaceThatsWhatAnInterfaceIsFor, IDynamicFlayTarget {
50+
public class BlockEntityPedestal extends BlockEntity implements Inventory, IReallyHateForgeWhyWouldAnInventoryInterfaceNotBeAnInterfaceThatsWhatAnInterfaceIsFor, IDynamicFlayTarget, IIoticProvider {
5051
public static final String ITEM_DATA_TAG = "inv_storage";
5152
public static final String PERSISTENT_UUID_TAG = "persistent_uuid";
5253

@@ -232,6 +233,11 @@ public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit){
232233
return ActionResult.SUCCESS;
233234
}
234235

236+
@Override
237+
public ADIotaHolder getIotaHolder(World world, BlockPos pos){
238+
return IXplatAbstractions.INSTANCE.findDataHolder(storedItem);
239+
}
240+
235241
@Override
236242
public void readNbt(NbtCompound nbt) {
237243
super.readNbt(nbt);

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

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class HexGloopBEs {
3232
= blockEntities.register(new Identifier(HexGloop.MOD_ID, "conjured_redstone_tile"),
3333
() -> BlockEntityType.Builder.create(BlockEntityConjuredRedstone::new, HexGloopBlocks.CONJURED_REDSTONE_BLOCK.get()).build(null));
3434

35+
public static RegistrySupplier<BlockEntityType<BlockEntityDial>> DIAL_BE
36+
= blockEntities.register(new Identifier(HexGloop.MOD_ID, "iotic_dial_tile"),
37+
() -> BlockEntityType.Builder.create(BlockEntityDial::new, HexGloopBlocks.IOTIC_DIAL_BLOCK.get()).build(null));
38+
3539
public static void register(){
3640
blockEntities.register();
3741
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package com.samsthenerd.hexgloop.blocks;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import javax.annotation.Nonnull;
7+
import javax.annotation.Nullable;
8+
9+
import com.samsthenerd.hexgloop.blockentities.BlockEntityDial;
10+
import com.samsthenerd.hexgloop.items.HexGloopItems;
11+
12+
import net.minecraft.block.Block;
13+
import net.minecraft.block.BlockRenderType;
14+
import net.minecraft.block.BlockState;
15+
import net.minecraft.block.BlockWithEntity;
16+
import net.minecraft.block.ShapeContext;
17+
import net.minecraft.block.entity.BlockEntity;
18+
import net.minecraft.entity.player.PlayerEntity;
19+
import net.minecraft.item.ItemPlacementContext;
20+
import net.minecraft.item.ItemStack;
21+
import net.minecraft.state.StateManager;
22+
import net.minecraft.state.property.DirectionProperty;
23+
import net.minecraft.state.property.IntProperty;
24+
import net.minecraft.state.property.Properties;
25+
import net.minecraft.util.ActionResult;
26+
import net.minecraft.util.Hand;
27+
import net.minecraft.util.Pair;
28+
import net.minecraft.util.hit.BlockHitResult;
29+
import net.minecraft.util.math.BlockPos;
30+
import net.minecraft.util.math.Direction;
31+
import net.minecraft.util.math.Vec3d;
32+
import net.minecraft.util.shape.VoxelShape;
33+
import net.minecraft.util.shape.VoxelShapes;
34+
import net.minecraft.world.BlockView;
35+
import net.minecraft.world.World;
36+
37+
public class BlockIoticDial extends BlockWithEntity {
38+
39+
public static final DirectionProperty FACING = Properties.FACING;
40+
public static final IntProperty SELECTED = IntProperty.of("selected", 0, 6);
41+
42+
public BlockIoticDial(Settings properties) {
43+
super(properties);
44+
setDefaultState(this.stateManager.getDefaultState()
45+
.with(FACING, Direction.NORTH)
46+
.with(SELECTED, 0)
47+
);
48+
}
49+
50+
public static final Map<Direction, VoxelShape> SHAPES = new HashMap<>();
51+
52+
static {
53+
SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0, 0, 11.0/16.0, 1, 1, 1));
54+
SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0, 0, 0, 1, 1, 5.0/16.0));
55+
SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0, 0, 0, 5.0/16.0, 1, 1));
56+
SHAPES.put(Direction.WEST, VoxelShapes.cuboid(11.0/16.0, 0, 0, 1, 1, 1));
57+
SHAPES.put(Direction.UP, VoxelShapes.cuboid(0, 0, 0, 1, 5.0/16.0, 1));
58+
SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0, 11.0/16.0, 0, 1, 1, 1));
59+
}
60+
61+
@Override
62+
@Nullable
63+
public BlockEntity createBlockEntity(BlockPos pos, BlockState state){
64+
return new BlockEntityDial(pos, state);
65+
}
66+
67+
@Override
68+
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
69+
return SHAPES.get(state.get(FACING));
70+
}
71+
72+
@Override
73+
public BlockState getPlacementState(ItemPlacementContext ctx) {
74+
return super.getPlacementState(ctx).with(FACING, ctx.getPlayerLookDirection().getOpposite());
75+
}
76+
77+
@Override
78+
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
79+
super.appendProperties(builder);
80+
builder.add(FACING);
81+
builder.add(SELECTED);
82+
}
83+
84+
@Override
85+
public boolean hasComparatorOutput(BlockState state) {
86+
return true;
87+
}
88+
89+
@Override
90+
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
91+
return state.get(SELECTED);
92+
}
93+
94+
@Nonnull
95+
@Override
96+
public BlockRenderType getRenderType( @Nonnull BlockState state )
97+
{
98+
return BlockRenderType.MODEL;
99+
}
100+
101+
private static Map<Direction.Axis, FaceCalcinator> faceCalcs = new HashMap<Direction.Axis, FaceCalcinator>();
102+
103+
static {
104+
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));
106+
faceCalcs.put(Direction.Axis.Z, (mirrored, pos) -> mirrored ? new Pair<>(1-pos.x, pos.y) : new Pair<>(pos.x, pos.y));
107+
};
108+
109+
@Override
110+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
111+
if(!(world.getBlockEntity(pos) instanceof BlockEntityDial dialBE)) return ActionResult.FAIL;
112+
if(dialBE.getInnerMultiFocus().isEmpty() && player.getStackInHand(hand).getItem() == HexGloopItems.MULTI_FOCUS_ITEM.get()){
113+
dialBE.setInnerMultiFocus(player.getStackInHand(hand).copy());
114+
player.getStackInHand(hand).decrement(1);
115+
return ActionResult.SUCCESS;
116+
}
117+
if(!dialBE.getInnerMultiFocus().isEmpty() && player.isSneaking()){
118+
player.getInventory().offerOrDrop(dialBE.getInnerMultiFocus());
119+
dialBE.setInnerMultiFocus(ItemStack.EMPTY);
120+
return ActionResult.SUCCESS;
121+
}
122+
Direction face = hit.getSide();
123+
Vec3d nPos = hit.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
124+
Pair<Double, Double> coords = faceCalcs.get(face.getAxis()).calc(face.getDirection() == Direction.AxisDirection.NEGATIVE, nPos);
125+
double r = new Vec3d(coords.getLeft()-0.5, coords.getRight()-0.5, 0).length();
126+
double angle = (Math.atan2(coords.getRight()-0.5, coords.getLeft()-0.5) + (2 * Math.PI)) % (2 * Math.PI);
127+
if(face == state.get(FACING)){
128+
int sel = (1 + 6 - (int)Math.floor(6 * angle / (2 * Math.PI))) % 6 + 1;
129+
dialBE.setSelection(sel);
130+
return ActionResult.SUCCESS;
131+
}
132+
return ActionResult.PASS;
133+
// HexGloop.logPrint("(" + coords.getLeft() + ", " + coords.getRight() + ")");
134+
}
135+
136+
@FunctionalInterface
137+
public static interface FaceCalcinator{
138+
public Pair<Double, Double> calc(boolean mirrored, Vec3d pos);
139+
}
140+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class HexGloopBlocks {
4646
() -> HexGloopBEs.SLATE_CHEST_BE.get(),
4747
true));
4848

49+
public static final RegistrySupplier<BlockIoticDial> IOTIC_DIAL_BLOCK = block("iotic_dial",
50+
() -> new BlockIoticDial(AbstractBlock.Settings.of(Material.AMETHYST, MapColor.GOLD).requiresTool().strength(4f, 4f).sounds(BlockSoundGroup.AMETHYST_BLOCK)));
51+
4952
public static final RegistrySupplier<BlockConjuredRedstone> CONJURED_REDSTONE_BLOCK = block("conjured_redstone",
5053
() -> new BlockConjuredRedstone(AbstractBlock.Settings.of(Material.AMETHYST, MapColor.TERRACOTTA_PURPLE).strength(1.5f, 6.0f).sounds(BlockSoundGroup.AMETHYST_BLOCK)),
5154
new Item.Settings()); // don't put it in item group

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

-34
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"variants": {
3+
"facing=up,selected=0": { "model": "hexgloop:block/iotic_dial/empty" },
4+
"facing=down,selected=0": { "model": "hexgloop:block/iotic_dial/empty", "x": 180 },
5+
"facing=north,selected=0": { "model": "hexgloop:block/iotic_dial/empty", "x": 270, "y": 180 },
6+
"facing=east,selected=0": { "model": "hexgloop:block/iotic_dial/empty", "x": 270, "y": 270 },
7+
"facing=south,selected=0": { "model": "hexgloop:block/iotic_dial/empty", "x": 270, "y": 0 },
8+
"facing=west,selected=0": { "model": "hexgloop:block/iotic_dial/empty", "x": 270, "y": 90 },
9+
10+
11+
"facing=up,selected=1": { "model": "hexgloop:block/iotic_dial/sel1" },
12+
"facing=down,selected=1": { "model": "hexgloop:block/iotic_dial/sel1", "x": 180 },
13+
"facing=north,selected=1": { "model": "hexgloop:block/iotic_dial/sel1", "x": 270, "y": 180 },
14+
"facing=east,selected=1": { "model": "hexgloop:block/iotic_dial/sel1", "x": 270, "y": 270 },
15+
"facing=south,selected=1": { "model": "hexgloop:block/iotic_dial/sel1", "x": 270, "y": 0 },
16+
"facing=west,selected=1": { "model": "hexgloop:block/iotic_dial/sel1", "x": 270, "y": 90 },
17+
18+
19+
"facing=up,selected=2": { "model": "hexgloop:block/iotic_dial/sel2" },
20+
"facing=down,selected=2": { "model": "hexgloop:block/iotic_dial/sel2", "x": 180 },
21+
"facing=north,selected=2": { "model": "hexgloop:block/iotic_dial/sel2", "x": 270, "y": 180 },
22+
"facing=east,selected=2": { "model": "hexgloop:block/iotic_dial/sel2", "x": 270, "y": 270 },
23+
"facing=south,selected=2": { "model": "hexgloop:block/iotic_dial/sel2", "x": 270, "y": 0 },
24+
"facing=west,selected=2": { "model": "hexgloop:block/iotic_dial/sel2", "x": 270, "y": 90 },
25+
26+
27+
"facing=up,selected=3": { "model": "hexgloop:block/iotic_dial/sel3" },
28+
"facing=down,selected=3": { "model": "hexgloop:block/iotic_dial/sel3", "x": 180 },
29+
"facing=north,selected=3": { "model": "hexgloop:block/iotic_dial/sel3", "x": 270, "y": 180 },
30+
"facing=east,selected=3": { "model": "hexgloop:block/iotic_dial/sel3", "x": 270, "y": 270 },
31+
"facing=south,selected=3": { "model": "hexgloop:block/iotic_dial/sel3", "x": 270, "y": 0 },
32+
"facing=west,selected=3": { "model": "hexgloop:block/iotic_dial/sel3", "x": 270, "y": 90 },
33+
34+
35+
"facing=up,selected=4": { "model": "hexgloop:block/iotic_dial/sel4" },
36+
"facing=down,selected=4": { "model": "hexgloop:block/iotic_dial/sel4", "x": 180 },
37+
"facing=north,selected=4": { "model": "hexgloop:block/iotic_dial/sel4", "x": 270, "y": 180 },
38+
"facing=east,selected=4": { "model": "hexgloop:block/iotic_dial/sel4", "x": 270, "y": 270 },
39+
"facing=south,selected=4": { "model": "hexgloop:block/iotic_dial/sel4", "x": 270, "y": 0 },
40+
"facing=west,selected=4": { "model": "hexgloop:block/iotic_dial/sel4", "x": 270, "y": 90 },
41+
42+
43+
"facing=up,selected=5": { "model": "hexgloop:block/iotic_dial/sel5" },
44+
"facing=down,selected=5": { "model": "hexgloop:block/iotic_dial/sel5", "x": 180 },
45+
"facing=north,selected=5": { "model": "hexgloop:block/iotic_dial/sel5", "x": 270, "y": 180 },
46+
"facing=east,selected=5": { "model": "hexgloop:block/iotic_dial/sel5", "x": 270, "y": 270 },
47+
"facing=south,selected=5": { "model": "hexgloop:block/iotic_dial/sel5", "x": 270, "y": 0 },
48+
"facing=west,selected=5": { "model": "hexgloop:block/iotic_dial/sel5", "x": 270, "y": 90 },
49+
50+
51+
"facing=up,selected=6": { "model": "hexgloop:block/iotic_dial/sel6" },
52+
"facing=down,selected=6": { "model": "hexgloop:block/iotic_dial/sel6", "x": 180 },
53+
"facing=north,selected=6": { "model": "hexgloop:block/iotic_dial/sel6", "x": 270, "y": 180 },
54+
"facing=east,selected=6": { "model": "hexgloop:block/iotic_dial/sel6", "x": 270, "y": 270 },
55+
"facing=south,selected=6": { "model": "hexgloop:block/iotic_dial/sel6", "x": 270, "y": 0 },
56+
"facing=west,selected=6": { "model": "hexgloop:block/iotic_dial/sel6", "x": 270, "y": 90 }
57+
58+
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"parent": "block/cube_bottom_top",
3+
"textures":{
4+
"bottom": "minecraft:block/gold_block",
5+
"top": "hexgloop:block/iotic_dial/top_base",
6+
"side": "hexgloop:block/iotic_dial/side"
7+
},
8+
"elements": [
9+
{
10+
"from": [ 0, 0, 0 ],
11+
"to": [ 16, 5, 16 ],
12+
"faces": {
13+
"down": { "texture": "#bottom", "cullface": "down" },
14+
"up": { "texture": "#top" },
15+
"north": { "texture": "#side", "uv": [ 0, 11, 16, 16 ], "cullface": "north" },
16+
"south": { "texture": "#side", "uv": [ 0, 11, 16, 16 ], "cullface": "south" },
17+
"west": { "texture": "#side", "uv": [ 0, 11, 16, 16 ], "cullface": "west" },
18+
"east": { "texture": "#side", "uv": [ 0, 11, 16, 16 ], "cullface": "east" }
19+
}
20+
}
21+
]
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parent": "hexgloop:block/iotic_dial/template",
3+
"textures":{
4+
"selected": "hexgloop:block/iotic_dial/selected/s0",
5+
"uns1": "hexgloop:block/iotic_dial/back/back1",
6+
"uns2": "hexgloop:block/iotic_dial/back/back2",
7+
"uns3": "hexgloop:block/iotic_dial/back/back3",
8+
"uns4": "hexgloop:block/iotic_dial/back/back4",
9+
"uns5": "hexgloop:block/iotic_dial/back/back5"
10+
}
11+
}

0 commit comments

Comments
 (0)