replace submodule with walksanatora/J65el02, BlockModificationEvent, and switch to using accessors over making everything public
parent
83fdc7b864
commit
157b53e1c3
@ -1,3 +1,4 @@
|
||||
|
||||
[submodule "J65el02"]
|
||||
path = J65el02
|
||||
url = git@git.broken-moon.net:astoriaFloyd/J65el02MC.git
|
||||
url = git@github.com:walksanatora/J65el02.git
|
||||
|
@ -0,0 +1,22 @@
|
||||
package net.brokenmoon.redcontrol.api.events;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class BlockModificationEvents {
|
||||
/**
|
||||
* this event is triggered when a blockstate is changed.
|
||||
*/
|
||||
public static Event<OnStateChange> ON_CHANGE = EventFactory.createArrayBacked(OnStateChange.class, callbacks -> (world,blockPos,oldState,newState) -> {
|
||||
for (OnStateChange callback : callbacks) {
|
||||
callback.onChange(world, blockPos,oldState,newState);
|
||||
}
|
||||
});
|
||||
public @FunctionalInterface interface OnStateChange {void onChange(@NotNull World world,@NotNull BlockPos blockPos,@NotNull BlockState oldState, @NotNull BlockState newState);}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package net.brokenmoon.redcontrol.mixin;
|
||||
|
||||
import com.simon816.j65el02.Bus;
|
||||
import com.simon816.j65el02.device.RedBus;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Bus.class)
|
||||
public interface BusAccessor {
|
||||
@Accessor(value = "redBus",remap = false)
|
||||
void setRedBus(RedBus redBus);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.brokenmoon.redcontrol.mixin;
|
||||
|
||||
import com.simon816.j65el02.Cpu;
|
||||
import com.simon816.j65el02.CpuState;
|
||||
import com.simon816.j65el02.device.RedBusState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Cpu.class)
|
||||
public interface CpuAccessor {
|
||||
@Accessor(value = "redBusState",remap = false)
|
||||
RedBusState getRedBusState();
|
||||
@Accessor(value = "state",remap = false)
|
||||
CpuState getState();
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package net.brokenmoon.redcontrol.mixin;
|
||||
|
||||
import com.simon816.j65el02.device.RedBus;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(RedBus.class)
|
||||
public interface RedBusAccessor {
|
||||
@Accessor(value = "peripherals",remap = false)
|
||||
RedBus.Peripheral[] getPeripherals();
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.brokenmoon.redcontrol.mixin;
|
||||
|
||||
import net.brokenmoon.redcontrol.api.events.BlockModificationEvents;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Debug;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Debug(export = true, print = true)
|
||||
@Mixin(World.class)
|
||||
public abstract class WorldMixin {
|
||||
@Unique
|
||||
private BlockState old;
|
||||
|
||||
@Shadow
|
||||
public BlockState getBlockState(BlockPos pos) {return null;}
|
||||
|
||||
@Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("RETURN"))
|
||||
private void hookBlockPlace(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> cir) {
|
||||
World world = (World)(Object)this;
|
||||
//IDEA says that this is unreachable but it is reachable.
|
||||
if (cir.getReturnValue() && !world.isClient()) {
|
||||
BlockModificationEvents.ON_CHANGE.invoker().onChange(world,pos,this.old,state);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD"))
|
||||
private void hookBlockRemove(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> cir) {
|
||||
this.old = getBlockState(pos);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"values": ["minecraft:glass"]
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "net.brokenmoon.redcontrol.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
"required": true,
|
||||
"package": "net.brokenmoon.redcontrol.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"BusAccessor",
|
||||
"CpuAccessor",
|
||||
"ExampleMixin",
|
||||
"RedBusAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue