package com.thebrokenrail.scriptcraft.api.bridge; import com.thebrokenrail.scriptcraft.core.ScriptCraftCore; import net.minecraft.block.BlockState; import net.minecraft.state.property.Property; import java.util.ArrayList; import java.util.Collection; import java.util.List; @SuppressWarnings({"rawtypes", "unchecked"}) class BlockStateBridges { static void register() { ScriptCraftCore.addBridge("BlockState.getBlock", args -> ((BlockState) args[0]).getBlock()); ScriptCraftCore.addBridge("BlockState.get", args -> { BlockState state = (BlockState) args[0]; String name = (String) args[1]; Collection> properties = state.getProperties(); for (Property property : properties) { if (property.getName().equals(name)) { return property.name(state.get(property)); } } return null; }); ScriptCraftCore.addBridge("BlockState.with", args -> { BlockState state = (BlockState) args[0]; String name = (String) args[1]; Comparable value = (Comparable) args[2]; Collection> properties = state.getProperties(); for (Property property : properties) { if (property.getName().equals(name)) { if (value instanceof String) { value = (Comparable) property.parse((String) value).orElse(null); } return state.with(property, value); } } return null; }); ScriptCraftCore.addBridge("BlockState.properties", args -> { BlockState state = (BlockState) args[0]; List names = new ArrayList<>(); Collection> properties = state.getProperties(); for (Property property : properties) { names.add(property.getName()); } return names.toArray(); }); ScriptCraftCore.addBridge("BlockState.isValid", args -> args[0] instanceof BlockState); } }