diff --git a/.gitignore b/.gitignore index 2ac281b..36c78fc 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,18 @@ run/* !run/addons/test/* logs/ + +*/build +/build +/bin +*/bin +/.gradle +*/.gradle +/minecraft +*/minecraft +/out +*/run +*/out +/run +/classes +logs/ \ No newline at end of file diff --git a/SandboxAPI b/SandboxAPI index 6b8bc8c..c684a4a 160000 --- a/SandboxAPI +++ b/SandboxAPI @@ -1 +1 @@ -Subproject commit 6b8bc8cf1914a2081fa69dfbd9d8debdce974a90 +Subproject commit c684a4aaf6de06e87c2e37ea813c7a6b899779de diff --git a/TestAddon/build.gradle b/TestAddon/build.gradle index 8665e58..2a87320 100644 --- a/TestAddon/build.gradle +++ b/TestAddon/build.gradle @@ -4,22 +4,20 @@ plugins { repositories { mavenCentral() - maven { url 'https://dl.bintray.com/sandboxpowered/API/' } - maven { url 'https://dl.bintray.com/sandboxpowered/Library/' } } dependencies { - implementation platform("org.sandboxpowered.api:api:0.4.+") + implementation platform("org.sandboxpowered.api:api:0.5.+") implementation "org.sandboxpowered.api:base" implementation "org.sandboxpowered.api:rendering" implementation "org.sandboxpowered.api:resources" - compileOnly group: 'org.jetbrains', name: 'annotations', version: '19.0.0' - implementation 'com.electronwill.night-config:core:3.6.0' - implementation 'com.electronwill.night-config:toml:3.6.0' implementation 'com.github.zafarkhaja:java-semver:0.9.0' implementation 'org.sandboxpowered:SimpleEventHandler:2.0.3' implementation group: 'com.google.guava', name: 'guava', version: '21.0' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' + implementation 'com.electronwill.night-config:toml:3.6.3' + implementation 'com.electronwill.night-config:core:3.6.3' + compileOnly 'org.jetbrains:annotations:20.1.0' } \ No newline at end of file diff --git a/TestAddon/src/main/java/org/sandboxpowered/example/Example.java b/TestAddon/src/main/java/org/sandboxpowered/example/Example.java index f5bbbf1..508ba87 100644 --- a/TestAddon/src/main/java/org/sandboxpowered/example/Example.java +++ b/TestAddon/src/main/java/org/sandboxpowered/example/Example.java @@ -2,52 +2,126 @@ import org.sandboxpowered.api.SandboxAPI; import org.sandboxpowered.api.addon.Addon; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.block.Blocks; -import org.sandboxpowered.api.block.Material; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; +import org.sandboxpowered.api.block.*; import org.sandboxpowered.api.events.BlockEvents; -import org.sandboxpowered.api.item.BaseBlockItem; +import org.sandboxpowered.api.events.ItemEvents; import org.sandboxpowered.api.item.BaseItem; import org.sandboxpowered.api.item.Item; import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.item.Items; +import org.sandboxpowered.api.item.tool.ToolItem; +import org.sandboxpowered.api.item.tool.ToolMaterial; +import org.sandboxpowered.api.item.tool.ToolMaterials; +import org.sandboxpowered.api.item.tool.ToolType; import org.sandboxpowered.api.registry.Registrar; -import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.resources.ResourceConstants; +import org.sandboxpowered.api.resources.ResourceMaterial; +import org.sandboxpowered.api.resources.ResourceService; import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -public class Example implements Addon { - public static BlockEntity.Type pipeEntityType; +import java.util.List; +public class Example implements Addon { @Override public void init(SandboxAPI api) { api.getLog().info("Loading Example Addon"); + BlockEvents.BREAK.subscribe((world, position, state, player, tool, cancellable) -> { + if (state.is(Blocks.BEDROCK)) + cancellable.cancel(); + }); + + ItemEvents.DRAW_STACK_COUNT.subscribe((stack, previous) -> { + return previous && !Items.DIAMOND.matches(stack.getItem()); + }); + ItemEvents.SHOW_DURABILITY_BAR.subscribe((stack, previous) -> { + return previous || Items.DIAMOND.matches(stack.getItem()) || stack.isDamageable(); + }); + ItemEvents.GET_DURABILITY_VALUE.subscribe((stack, previous) -> { + if (Items.DIAMOND.matches(stack.getItem())) + return stack.getCount() / (float) stack.getMaxCount(); + return previous; + }); + ItemEvents.GET_DURABILITY_COLOR.subscribe((stack, previous) -> { + if (Items.DIAMOND.matches(stack.getItem())) return 0x15CCEC; + return previous; + }); + BlockEvents.INTERACT.subscribe((world, position, state, player, hand, stack, result) -> { if (result != InteractionResult.IGNORE) return result; - if (!stack.getItem().getIdentity().getPath().contains("shovel")) - return InteractionResult.IGNORE; - if(!state.is(Blocks.DIRT) || !world.getBlockState(position.up()).isAir()) + if (world.isClient()) return InteractionResult.IGNORE; - if(world.isServer()) { - world.setBlockState(position, Blocks.GRASS_PATH.get()); - stack.damage(1, player); + Block block = state.getBlock(); + if (block instanceof CropBlock) { + CropBlock crop = (CropBlock) block; + int age = crop.getAge(state); + if (age >= crop.getMaxAge()) { + List drops = block.getDrops(world, position, state); + + boolean foundSeed = false; + + for (ItemStack drop : drops) { + if (drop.isEmpty()) + continue; + + if (drop.getItem() == crop.getSeed()) { + drop.shrink(1); + foundSeed = true; + break; + } + } + + if (foundSeed) { + if (world.isServer()) { + world.setBlockState(position, crop.stateForAge(0)); + for (ItemStack drop : drops) { + world.spawnItem(position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5, drop); + } + } + return InteractionResult.SUCCESS; + } + } } - return InteractionResult.SUCCESS; + return InteractionResult.IGNORE; }); } + public void registerMaterials(ResourceService service) { + service.add(ResourceConstants.IRON, ResourceConstants.INGOT); + service.add(ResourceConstants.GOLD, ResourceConstants.INGOT); + service.add(ResourceConstants.COPPER, + ResourceConstants.INGOT, + ResourceConstants.ORE, + ResourceConstants.NUGGET, + ResourceConstants.BLOCK + ); + } + @Override - public void register(Registrar registrar) { - PipeBlock pipe = new PipeBlock(Block.Settings.builder(Material.METAL).build()); - pipeEntityType = BlockEntity.Type.of(() -> new PipeBlockEntity(pipeEntityType), pipe); - registrar.register("pipe", pipe); - registrar.register("pipe", pipeEntityType); - registrar.register("pipe", new BaseBlockItem(pipe, new Item.Settings())); + public void register(SandboxAPI api, Registrar registrar) { + registrar.useRegistrarService(ResourceService.class, this::registerMaterials); registrar.register("test", new BaseItem(new Item.Settings())); + registrar.register("block", new BaseBlock(Block.Settings.builder(Materials.STONE).setLuminance(-1).build())); + registrar.register("block_no_itemblock", new BaseBlock(Block.Settings.builder(Materials.STONE).removeItemBlock().build())); + + registrar.register("wooden_paxel", createPaxel(ToolMaterials.WOOD, 6.0F, -3.2F)); + registrar.register("stone_paxel", createPaxel(ToolMaterials.STONE, 7.0F, -3.2F)); + registrar.register("iron_paxel", createPaxel(ToolMaterials.IRON, 6.0F, -3.1F)); + registrar.register("golden_paxel", createPaxel(ToolMaterials.GOLD, 6.0F, -3.0F)); + registrar.register("diamond_paxel", createPaxel(ToolMaterials.DIAMOND, 5.0F, -3.0F)); + registrar.register("netherite_paxel", createPaxel(ToolMaterials.NETHERITE, 5.0F, -3.0F)); + } + + public ToolItem createPaxel(ToolMaterial material, float damageIn, float speedIn) { + return new ToolItem(material, damageIn, speedIn, new Item.Settings() + .addToolTypes(material, + ToolType.PICKAXE, + ToolType.AXE, + ToolType.SHOVEL, + ToolType.STRIPPER, + ToolType.PAVER + ) + ); } } \ No newline at end of file diff --git a/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlock.java b/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlock.java deleted file mode 100644 index c221615..0000000 --- a/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlock.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.sandboxpowered.example; - -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.BaseBlock; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.client.GraphicsMode; -import org.sandboxpowered.api.component.Components; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.shape.Shape; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.state.Properties; -import org.sandboxpowered.api.state.Property; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Vec3d; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.api.world.WorldReader; - -import java.util.IdentityHashMap; -import java.util.Map; - -public class PipeBlock extends BaseBlock { - public static final Shape CORE = Shape.cuboid(4, 4, 4, 12, 12, 12); - protected static final Property[] CONNECTION_PROPERTIES = new Property[Direction.ALL.length]; - public static final Property UP = Properties.UP; - public static final Property DOWN = Properties.DOWN; - public static final Property NORTH = Properties.NORTH; - public static final Property EAST = Properties.EAST; - public static final Property SOUTH = Properties.SOUTH; - public static final Property WEST = Properties.WEST; - private static final Shape[] SIDE_SHAPES = new Shape[Direction.ALL.length]; - public static final Shape CENTER_SHAPE; - - static { - CENTER_SHAPE = Shape.cuboid(4, 4, 4, 12, 12, 12); - CONNECTION_PROPERTIES[Direction.UP.getId()] = UP; - CONNECTION_PROPERTIES[Direction.DOWN.getId()] = DOWN; - CONNECTION_PROPERTIES[Direction.NORTH.getId()] = NORTH; - CONNECTION_PROPERTIES[Direction.EAST.getId()] = EAST; - CONNECTION_PROPERTIES[Direction.SOUTH.getId()] = SOUTH; - CONNECTION_PROPERTIES[Direction.WEST.getId()] = WEST; - - SIDE_SHAPES[Direction.UP.getId()] = Shape.cuboid(4, 12, 4, 12, 16, 12); - SIDE_SHAPES[Direction.DOWN.getId()] = Shape.cuboid(4, 0, 4, 12, 4, 12); - SIDE_SHAPES[Direction.NORTH.getId()] = Shape.cuboid(4, 4, 0, 12, 12, 4); - SIDE_SHAPES[Direction.EAST.getId()] = Shape.cuboid(12, 4, 4, 16, 12, 12); - SIDE_SHAPES[Direction.SOUTH.getId()] = Shape.cuboid(4, 4, 12, 12, 12, 16); - SIDE_SHAPES[Direction.WEST.getId()] = Shape.cuboid(0, 4, 4, 4, 12, 12); - } - - private final Map shapeCache = new IdentityHashMap<>(); - - public PipeBlock(Settings settings) { - super(settings); - } - - private static Shape computeShape(BlockState state) { - Shape shape = CORE; - for (Direction direction : Direction.ALL) { - if (state.get(CONNECTION_PROPERTIES[direction.getId()])) { - shape = shape.combine(SIDE_SHAPES[direction.getId()]).simplify(); - } - } - return shape; - } - - @Override - public boolean hasBlockEntity() { - return true; - } - - @Override - public @Nullable BlockEntity createBlockEntity(WorldReader reader) { - return new PipeBlockEntity(Example.pipeEntityType); - } - - @Override - public void appendProperties(StateFactory.Builder builder) { - super.appendProperties(builder); - builder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST); - } - - @Override - public BlockState getStateForPlacement(WorldReader reader, Position pos, PlayerEntity player, Hand hand, ItemStack stack, Direction side, Vec3d hitPos) { - BlockState state = getBaseState(); - for (Direction direction : Direction.ALL) { - Position offsetPos = pos.offset(direction); - state = state.with(CONNECTION_PROPERTIES[direction.getId()], canConnectTo(reader, offsetPos, reader.getBlockState(offsetPos))); - } - return state; - } - - public boolean canConnectTo(WorldReader reader, Position pos, BlockState state) { - return state.getBlock() instanceof PipeBlock || state.getComponent(reader, pos, Components.INVENTORY_COMPONENT).isPresent(); - } - - @Override - public BlockState updateOnNeighborChanged(BlockState state, Direction direction, BlockState otherState, World world, Position position, Position otherPosition) { - return state.with(CONNECTION_PROPERTIES[direction.getId()], canConnectTo(world, otherPosition, otherState)); - } - - @Override - public BlockRenderLayer getRenderLayer(BlockState state, GraphicsMode mode) { - return mode.isFancyOrBetter() ? BlockRenderLayer.CUTOUT_MIPPED : BlockRenderLayer.SOLID; - } - - @Override - public Shape getShape(WorldReader reader, Position position, BlockState state) { - return shapeCache.computeIfAbsent(state, PipeBlock::computeShape); - } -} \ No newline at end of file diff --git a/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlockEntity.java b/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlockEntity.java deleted file mode 100644 index 2d85ee1..0000000 --- a/TestAddon/src/main/java/org/sandboxpowered/example/PipeBlockEntity.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sandboxpowered.example; - -import org.sandboxpowered.api.block.entity.BaseBlockEntity; -import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; -import org.sandboxpowered.api.util.nbt.WritableCompoundTag; - -public class PipeBlockEntity extends BaseBlockEntity { - public PipeBlockEntity(Type type) { - super(type); - } - - @Override - public void read(ReadableCompoundTag tag) { - - } - - @Override - public void write(WritableCompoundTag tag) { - - } -} diff --git a/TestAddon/src/main/java/org/sandboxpowered/example/package-info.java b/TestAddon/src/main/java/org/sandboxpowered/example/package-info.java new file mode 100644 index 0000000..e05cd18 --- /dev/null +++ b/TestAddon/src/main/java/org/sandboxpowered/example/package-info.java @@ -0,0 +1,8 @@ + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.example; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/TestAddon/src/main/resources/assets/exampleaddon/lang/en_us.json b/TestAddon/src/main/resources/assets/exampleaddon/lang/en_us.json new file mode 100644 index 0000000..bdb4ab2 --- /dev/null +++ b/TestAddon/src/main/resources/assets/exampleaddon/lang/en_us.json @@ -0,0 +1,8 @@ +{ + "item.exampleaddon.wooden_paxel": "Wooden Paxel", + "item.exampleaddon.stone_paxel": "Stone Paxel", + "item.exampleaddon.iron_paxel": "Iron Paxel", + "item.exampleaddon.golden_paxel": "Golden Paxel", + "item.exampleaddon.diamond_paxel": "Diamond Paxel", + "item.exampleaddon.netherite_paxel": "Netherite Paxel" +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/diamond_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/diamond_paxel.json new file mode 100644 index 0000000..1a477e4 --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/diamond_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:diamond_pickaxe" + }, + "A": { + "item": "minecraft:diamond_axe" + }, + "S": { + "item": "minecraft:diamond_shovel" + } + }, + "result": { + "item": "exampleaddon:diamond_paxel" + } +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/gold_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/gold_paxel.json new file mode 100644 index 0000000..caf8bce --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/gold_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:golden_pickaxe" + }, + "A": { + "item": "minecraft:golden_axe" + }, + "S": { + "item": "minecraft:golden_shovel" + } + }, + "result": { + "item": "exampleaddon:golden_paxel" + } +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/iron_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/iron_paxel.json new file mode 100644 index 0000000..e0b70e1 --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/iron_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:iron_pickaxe" + }, + "A": { + "item": "minecraft:iron_axe" + }, + "S": { + "item": "minecraft:iron_shovel" + } + }, + "result": { + "item": "exampleaddon:iron_paxel" + } +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/netherite_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/netherite_paxel.json new file mode 100644 index 0000000..3b31089 --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/netherite_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:netherite_pickaxe" + }, + "A": { + "item": "minecraft:netherite_axe" + }, + "S": { + "item": "minecraft:netherite_shovel" + } + }, + "result": { + "item": "exampleaddon:netherite_paxel" + } +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/stone_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/stone_paxel.json new file mode 100644 index 0000000..dae9705 --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/stone_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:stone_pickaxe" + }, + "A": { + "item": "minecraft:stone_axe" + }, + "S": { + "item": "minecraft:stone_shovel" + } + }, + "result": { + "item": "exampleaddon:stone_paxel" + } +} \ No newline at end of file diff --git a/TestAddon/src/main/resources/data/exampleaddon/recipes/wooden_paxel.json b/TestAddon/src/main/resources/data/exampleaddon/recipes/wooden_paxel.json new file mode 100644 index 0000000..df6151e --- /dev/null +++ b/TestAddon/src/main/resources/data/exampleaddon/recipes/wooden_paxel.json @@ -0,0 +1,28 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "PSA", + " B ", + " # " + ], + "key": { + "#": { + "item": "minecraft:stick" + }, + "B": { + "item": "minecraft:slime_ball" + }, + "P": { + "item": "minecraft:wooden_pickaxe" + }, + "A": { + "item": "minecraft:wooden_axe" + }, + "S": { + "item": "minecraft:wooden_shovel" + } + }, + "result": { + "item": "exampleaddon:wooden_paxel" + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index e6db096..7433f3d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,125 +1,59 @@ plugins { - id 'fabric-loom' version '0.5-SNAPSHOT' - id 'java-library' - id 'maven-publish' - id 'me.qoomon.git-versioning' version '3.0.0' - id "org.sonarqube" version "3.0" + id 'java' + id "architectury-plugin" version "1.3.48" + id "forgified-fabric-loom" version "0.5.30" apply false } - -sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 - -def releasesRepoUrl = "https://nexus.sandboxpowered.org/repository/maven-releases/" -def snapshotsRepoUrl = "https://nexus.sandboxpowered.org/repository/maven-snapshots/" -def ENV = System.getenv() -archivesBaseName = project.archives_base_name -group = project.maven_group -version = "${project.sandbox_version}-SNAPSHOT" -gitVersioning.apply { - branch { - pattern = 'develop' - versionFormat = '${version}' - } - branch { - pattern = 'feature/(?.+)' - versionFormat = '${feature}-SNAPSHOT' - } - tag { - pattern = 'release/(?[0-9].*)' - versionFormat = '${tagVersion}' - } - commit { - versionFormat = '${commit.short}' - } -} - -minecraft { - accessWidener = file("src/main/resources/META-INF/sandbox-fabric.accesswidener") -} - -allprojects { - apply plugin: 'java' -} - -repositories { - maven { url 'https://nexus.sandboxpowered.org/repository/maven-public/' } -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_mappings}" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - compileOnly 'com.google.code.findbugs:jsr305:3.0.2' - runtimeOnly('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1') { - transitive = false - } - runtimeOnly project(':TestAddon') - - implementation platform('org.sandboxpowered.api:api:0.4.+') - - include implementation('org.sandboxpowered.api:base') - include implementation('org.sandboxpowered.api:rendering') - include implementation('org.sandboxpowered.api:resources') - - compileOnly 'org.jetbrains:annotations:19.0.0' - include implementation( 'com.electronwill.night-config:core:3.6.0') - include implementation('com.electronwill.night-config:toml:3.6.0') - include implementation('com.github.zafarkhaja:java-semver:0.9.0') - include implementation('org.sandboxpowered:SimpleEventHandler:2.0.3') - implementation 'com.google.guava:guava:21.0' - implementation 'org.apache.commons:commons-lang3:3.9' +architect { + minecraft = rootProject.minecraft_version } -processResources { - inputs.property "version", project.version +subprojects { + apply plugin: "java" + if(name != "TestAddon") { + apply plugin: "architectury-plugin" + apply plugin: "forgified-fabric-loom" - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" - expand "version": project.version + loom { + silentMojangMappingsLicense() + } } - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } } -} -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" -} + archivesBaseName = rootProject.archives_base_name + version = rootProject.mod_version + group = rootProject.maven_group -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource -} - -jar { - from "LICENSE" -} - -sonarqube { - properties { - property "sonar.projectKey", "SandboxPowered_Sandbox" - property "sonar.organization", "sandboxpowered" - property "sonar.host.url", "https://sonarcloud.io" - } -} - -publishing { - publications { - maven(MavenPublication) { - artifact remapJar - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } + tasks.withType(JavaCompile) { + options.encoding = "UTF-8" } repositories { + maven { url 'https://nexus.sandboxpowered.org/repository/maven-public/' } maven { - url = rootProject.version.endsWith("-SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl - credentials { - username ENV.MAVEN_USER - password ENV.MAVEN_PASS - } + name = "JitPack" + url = "https://jitpack.io" } } -} + + dependencies { + implementation enforcedPlatform('org.sandboxpowered.api:api:+') + + implementation('org.sandboxpowered.api:base') + implementation('org.sandboxpowered.api:rendering') + implementation('org.sandboxpowered.api:resources') + + compileOnly 'org.jetbrains:annotations:19.0.0' + implementation( 'com.electronwill.night-config:core:3.6.0') + implementation('com.electronwill.night-config:toml:3.6.0') + implementation('com.github.zafarkhaja:java-semver:0.9.0') + implementation('org.sandboxpowered:SimpleEventHandler:2.0.3') + implementation 'com.google.guava:guava:21.0' + implementation 'org.apache.commons:commons-lang3:3.9' + implementation 'commons-io:commons-io:2.5' + } +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..1caff2a --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,19 @@ +String graalVersion = "21.0.0" + +dependencies { + minecraft "com.mojang:minecraft:${rootProject.architect.minecraft}" + mappings minecraft.officialMojangMappings() + modCompile "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + + implementation "org.graalvm.sdk:graal-sdk:$graalVersion" + implementation "org.graalvm.js:js:$graalVersion" + implementation "net.jodah:typetools:0.6.2" +} + +architect { + common() +} + +loom { + accessWidener "src/main/resources/sandbox.accesswidener" +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/CacheableRegistry.java b/common/src/main/java/org/sandboxpowered/loader/CacheableRegistry.java new file mode 100644 index 0000000..5b13c0d --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/CacheableRegistry.java @@ -0,0 +1,19 @@ +package org.sandboxpowered.loader; + +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.registry.Registry; + +public interface CacheableRegistry, V> { + void setWrapper(Wrappers.Wrapper wrapper); + + Registry getSandboxRegistry(); + + void saveRegistryContent(); + + void resetRegistryContent(); + + interface Wrapped, V> { + net.minecraft.core.Registry toVanilla(); + Registry toSandbox(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/SandboxCore.java b/common/src/main/java/org/sandboxpowered/loader/SandboxCore.java new file mode 100644 index 0000000..b52dc48 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/SandboxCore.java @@ -0,0 +1,137 @@ +package org.sandboxpowered.loader; + +import com.google.common.base.Throwables; +import com.google.inject.Inject; +import net.minecraft.core.Registry; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.item.*; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.LevelStorageSource; +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.item.tool.ToolType; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.config.Config; +import org.sandboxpowered.loader.loading.AddonSecurityPolicy; +import org.sandboxpowered.loader.loading.SandboxLoader; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.sandboxpowered.loader.wrapper.IVanillaBlock; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.lang.reflect.Field; +import java.security.Policy; +import java.util.Arrays; +import java.util.Set; + +public abstract class SandboxCore implements SandboxPlatform { + protected Config config; + @Inject + protected Logger logger; + + protected SandboxLoader loader = new SandboxLoader(); + + public SandboxCore() { + try { + config = new Config("data/sandbox/sandbox.toml"); + } catch (IOException e) { + getLog().error("Error creating configuration file", e); + return; + } + + config.save(); + } + + @Override + public void load(MinecraftServer server, LevelStorageSource.LevelStorageAccess storageSource) { + if (loader.isLoaded()) { + throw new UnsupportedOperationException("Cannot load Sandbox if in already loaded state"); + } + loader.load(server, storageSource); + } + + @Override + public void unload() { + if (!loader.isLoaded()) { + throw new UnsupportedOperationException("Cannot unload Sandbox if in unloaded state"); + } + loader.unload(); + } + + @Override + public void init() { + Policy.setPolicy(new AddonSecurityPolicy()); + initCachedRegistries(); + + initToolTypes(); + } + + private void initToolTypes() { + Set blocks = getPrivateField(PickaxeItem.class, null, 0); + blocks.forEach((block) -> setValue(block, ToolType.PICKAXE, 0)); + + blocks = getPrivateField(ShovelItem.class, null, 0); + blocks.forEach((block) -> setValue(block, ToolType.SHOVEL, 0)); + + Set materials = getPrivateField(AxeItem.class, null, 0); + Set pickMats = Set.of(Material.STONE, Material.METAL, Material.HEAVY_METAL); + + for (Block block : Registry.BLOCK) { + if (materials.contains(block.defaultBlockState().getMaterial())) { + setValue(block, ToolType.AXE, 0); + } + if (pickMats.contains(block.defaultBlockState().getMaterial())) { + setValue(block, ToolType.PICKAXE, 0); + } + } + + blocks = getPrivateField(AxeItem.class, null, 1); + blocks.forEach((block) -> setValue(block, ToolType.AXE, 0)); + blocks = getPrivateField(HoeItem.class, null, 0); + blocks.forEach((block) -> setValue(block, ToolType.HOE, 0)); + + Arrays.stream(new Block[]{Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE}) + .forEach(block -> setValue(block, ToolType.PICKAXE, 1)); + Arrays.stream(new Block[]{Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.EMERALD_ORE, Blocks.EMERALD_BLOCK, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.REDSTONE_ORE}) + .forEach(block -> setValue(block, ToolType.PICKAXE, 2)); + Arrays.stream(new Block[]{Blocks.OBSIDIAN, Blocks.CRYING_OBSIDIAN, Blocks.NETHERITE_BLOCK, Blocks.RESPAWN_ANCHOR, Blocks.ANCIENT_DEBRIS}) + .forEach(block -> setValue(block, ToolType.PICKAXE, 3)); + } + + private static void setValue(Block block, ToolType type, int level) { + ((IVanillaBlock)block).sandbox_setHarvestParams(type, level); + } + + private static T getPrivateField(Class classToAccess, @Nullable E instance, int fieldIndex) { + try { + Field f = classToAccess.getDeclaredFields()[fieldIndex]; + f.setAccessible(true); + return (T) f.get(instance); + } catch (Exception var4) { + Throwables.throwIfUnchecked(var4); + throw new RuntimeException(var4); + } + } + + @Override + public Identity getIdentity() { + return loader.getPlatform(); + } + + @Override + public boolean isLoaded() { + return loader.isLoaded(); + } + + @Override + public SandboxLoader getLoader() { + return loader; + } + + protected abstract void initCachedRegistries(); + + public Logger getLog() { + return logger; + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/Wrappers.java b/common/src/main/java/org/sandboxpowered/loader/Wrappers.java new file mode 100644 index 0000000..f393410 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/Wrappers.java @@ -0,0 +1,249 @@ +package org.sandboxpowered.loader; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.item.Tier; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.block.Material; +import org.sandboxpowered.api.enchantment.Enchantment; +import org.sandboxpowered.api.fluid.Fluid; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.item.attribute.Attribute; +import org.sandboxpowered.api.item.tool.ToolMaterial; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.util.EquipmentSlot; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.api.util.InteractionResult; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.util.text.Text; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.api.world.WorldReader; +import org.sandboxpowered.loader.wrapper.WrappedBlock; +import org.sandboxpowered.loader.wrapper.WrappedItem; + +import java.util.Collection; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class Wrappers { + public static final Wrapper ITEM = new Wrapper<>( + Item.class, net.minecraft.world.item.Item.class, + WrappedItem::convertSandboxItem, + WrappedItem::convertVanillaItem + ); + public static final Wrapper TEXT = new Wrapper<>( + Text.class, Component.class + ); + public static final Wrapper WORLD = new Wrapper<>( + World.class, Level.class + ); + public static final Wrapper WORLD_READER = new Wrapper<>( + WorldReader.class, BlockGetter.class + ); + public static final Wrapper BLOCKSTATE = new Wrapper<>( + org.sandboxpowered.api.state.BlockState.class, BlockState.class + ); + public static final Wrapper POSITION = new Wrapper<>( + Position.class, BlockPos.class + ); + public static final Wrapper REGISTRY = new Wrapper<>( + Registry.class, net.minecraft.core.Registry.class, + s -> { + if (s instanceof CacheableRegistry.Wrapped) + return ((CacheableRegistry.Wrapped) s).toVanilla(); + return null; + }, + v -> { + if (v instanceof CacheableRegistry) + return ((CacheableRegistry) v).getSandboxRegistry(); + return null; + } + ); + public static final Wrapper INTERACTION_RESULT = new Wrapper<>( + InteractionResult.class, net.minecraft.world.InteractionResult.class, + result -> { + switch (result) { + case CONSUME: + return net.minecraft.world.InteractionResult.CONSUME; + case SUCCESS: + return net.minecraft.world.InteractionResult.SUCCESS; + case FAILURE: + return net.minecraft.world.InteractionResult.FAIL; + default: + return net.minecraft.world.InteractionResult.PASS; + } + }, + result -> { + switch (result) { + case CONSUME: + return InteractionResult.CONSUME; + case SUCCESS: + return InteractionResult.SUCCESS; + case FAIL: + return InteractionResult.FAILURE; + default: + return InteractionResult.IGNORE; + } + } + ); + public static final Wrapper MATERIAL = new Wrapper<>( + Material.class, net.minecraft.world.level.material.Material.class + ); + public static final Wrapper MUTABLE_POSITION = new Wrapper<>( + Position.Mutable.class, BlockPos.MutableBlockPos.class + ); + public static final Wrapper ATTRIBUTE = new Wrapper<>( + Attribute.class, net.minecraft.world.entity.ai.attributes.Attribute.class + ); + public static final Wrapper TOOL_MATERIAL = new Wrapper<>( + ToolMaterial.class, Tier.class + ); + public static final Wrapper BLOCK = new Wrapper<>( + Block.class, net.minecraft.world.level.block.Block.class, + WrappedBlock::convertSandboxBlock, + WrappedBlock::convertVanillaBlock + ); + public static final Wrapper FLUID = new Wrapper<>( + Fluid.class, net.minecraft.world.level.material.Fluid.class, + fluid -> null, + fluid -> null + ); + public static final Wrapper ENCHANTMENT = new Wrapper<>( + Enchantment.class, net.minecraft.world.item.enchantment.Enchantment.class, + enchant -> null, + enchant -> null + ); + + public static final Wrapper IDENTITY = new Wrapper<>( + Identity.class, ResourceLocation.class + ); + + public static final Wrapper ITEMSTACK = new Wrapper<>( + ItemStack.class, net.minecraft.world.item.ItemStack.class + ); + public static final Wrapper EQUIPMENT_SLOT = new Wrapper<>( + EquipmentSlot.class, net.minecraft.world.entity.EquipmentSlot.class, + slot -> { + switch (slot) { + case MAIN_HAND: + return net.minecraft.world.entity.EquipmentSlot.MAINHAND; + case FEET: + return net.minecraft.world.entity.EquipmentSlot.FEET; + case LEGS: + return net.minecraft.world.entity.EquipmentSlot.LEGS; + case CHEST: + return net.minecraft.world.entity.EquipmentSlot.CHEST; + case HEAD: + return net.minecraft.world.entity.EquipmentSlot.HEAD; + case OFF_HAND: + default: + return net.minecraft.world.entity.EquipmentSlot.OFFHAND; + } + }, + slot -> { + switch (slot) { + case MAINHAND: + return EquipmentSlot.MAIN_HAND; + case FEET: + return EquipmentSlot.FEET; + case LEGS: + return EquipmentSlot.LEGS; + case CHEST: + return EquipmentSlot.CHEST; + case HEAD: + return EquipmentSlot.HEAD; + case OFFHAND: + default: + return EquipmentSlot.OFF_HAND; + } + } + ); + public static final Wrapper ATTRIBUTE_MODIFIER = new Wrapper<>( + Attribute.Modifier.class, AttributeModifier.class + ); + public static final Wrapper ATTRIBUTE_OPERATION = new Wrapper<>( + Attribute.Operation.class, AttributeModifier.Operation.class, + operation -> { + switch (operation) { + case MULTIPLY_BASE: + return AttributeModifier.Operation.MULTIPLY_BASE; + case MULTIPLY_TOTAL: + return AttributeModifier.Operation.MULTIPLY_TOTAL; + case ADDITION: + default: + return AttributeModifier.Operation.ADDITION; + } + }, + operation -> { + switch (operation) { + case MULTIPLY_BASE: + return Attribute.Operation.MULTIPLY_BASE; + case MULTIPLY_TOTAL: + return Attribute.Operation.MULTIPLY_TOTAL; + case ADDITION: + default: + return Attribute.Operation.ADDITION; + } + } + ); + + private static Function cast() { + return i -> (Y) i; + } + + public static class Wrapper { + private final Class sandboxType; + private final Class vanillaType; + private final Function sandboxToVanilla; + private final Function vanillaToSandbox; + private final Function, Collection> sandboxToVanillaCollection; + private final Function, Collection> vanillaToSandboxCollection; + + public Wrapper(Class sandboxType, Class vanillaType, Function sandboxToVanilla, Function vanillaToSandbox) { + this(sandboxType, vanillaType, sandboxToVanilla, vanillaToSandbox, c -> c.stream().map(sandboxToVanilla).collect(Collectors.toSet()), c -> c.stream().map(vanillaToSandbox).collect(Collectors.toList())); + } + + public Wrapper(Class sandboxType, Class vanillaType) { + this(sandboxType, vanillaType, cast(), cast(), cast(), cast()); + } + + public Wrapper(Class sandboxType, Class vanillaType, Function sandboxToVanilla, Function vanillaToSandbox, Function, Collection> sandboxToVanillaCollection, Function, Collection> vanillaToSandboxCollection) { + this.sandboxType = sandboxType; + this.vanillaType = vanillaType; + this.sandboxToVanilla = sandboxToVanilla; + this.vanillaToSandbox = vanillaToSandbox; + this.sandboxToVanillaCollection = sandboxToVanillaCollection; + this.vanillaToSandboxCollection = vanillaToSandboxCollection; + } + + public V toVanilla(S sandbox) { + return sandboxToVanilla.apply(sandbox); + } + + public S toSandbox(V vanilla) { + return vanillaToSandbox.apply(vanilla); + } + + public Class getSandboxType() { + return sandboxType; + } + + public Class getVanillaType() { + return vanillaType; + } + + public Collection toSandboxList(Collection collection) { + return vanillaToSandboxCollection.apply(collection); + } + + public Collection toVanillaList(Collection collection) { + return sandboxToVanillaCollection.apply(collection); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/config/Config.java b/common/src/main/java/org/sandboxpowered/loader/config/Config.java new file mode 100644 index 0000000..9b4ddb9 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/config/Config.java @@ -0,0 +1,112 @@ +package org.sandboxpowered.loader.config; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class Config { + private final CommentedFileConfig config; + + public Config(String path) throws IOException { + Path p = Paths.get(path); + Files.createDirectories(p.getParent()); + this.config = CommentedFileConfig.builder(p).build(); + load(); + } + + public void setPathComment(String path, String comment) { + config.setComment(path, comment); + } + + public GenericConfigValue value(String s) { + return new GenericConfigValue<>(s); + } + + public > EnumConfigValue enumValue(String s, Class enumClass) { + return new EnumConfigValue<>(s, enumClass); + } + + public void save() { + config.save(); + } + + public void load() { + config.load(); + } + + private interface Value { + T get(); + + void set(T value); + + void setIfAbsent(T value); + + String getComment(); + + void setComment(String comment); + } + + private abstract class BaseConfigValue implements Value { + protected final String path; + + public BaseConfigValue(String path) { + this.path = path; + } + + @Override + public String getComment() { + return config.getComment(path); + } + + @Override + public void setComment(String comment) { + config.setComment(path, comment); + } + + @Override + public void set(T value) { + config.set(path, value); + } + + @Override + public void setIfAbsent(T value) { + config.add(path, value); + } + } + + private class EnumConfigValue> extends BaseConfigValue { + private final Class enumClass; + + public EnumConfigValue(String path, Class enumClass) { + super(path); + this.enumClass = enumClass; + } + + @Override + public T get() { + return config.getEnum(path, enumClass); + } + } + + public class GenericConfigValue extends BaseConfigValue { + public GenericConfigValue(String path) { + super(path); + } + + @Override + public T get() { + return config.get(path); + } + + public boolean getAsBoolean() { + return config.get(path); + } + + public int getAsInt() { + return config.getInt(path); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/config/package-info.java b/common/src/main/java/org/sandboxpowered/loader/config/package-info.java new file mode 100644 index 0000000..e4c9569 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/config/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.config; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/SandboxFactoryProvider.java b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxFactoryProvider.java new file mode 100644 index 0000000..ca71a24 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxFactoryProvider.java @@ -0,0 +1,76 @@ +package org.sandboxpowered.loader.inject; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.google.inject.Singleton; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Tiers; +import org.checkerframework.checker.units.qual.A; +import org.sandboxpowered.api.block.Material; +import org.sandboxpowered.api.block.Materials; +import org.sandboxpowered.api.events.EventHandlerFactory; +import org.sandboxpowered.api.inject.FactoryProvider; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.item.attribute.Attribute; +import org.sandboxpowered.api.item.attribute.Attributes; +import org.sandboxpowered.api.item.tool.ToolMaterials; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.eventhandler.ResettableEventHandler; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.inject.factory.*; + +import java.util.Map; +import java.util.Objects; + +@Singleton +public class SandboxFactoryProvider implements FactoryProvider { + private final Map, Object> factories = new Object2ObjectOpenHashMap<>(); + + public SandboxFactoryProvider() { + registerDefaultFactories(); + } + + @Override + public T get(Class factoryClass) throws FactoryNotFoundException { + final Object factory = this.factories.get(factoryClass); + if (factory == null) + throw new FactoryNotFoundException(String.format("Type '%s' has no factory.", factoryClass)); + return (T) factory; + } + + @CanIgnoreReturnValue + public SandboxFactoryProvider registerFactory(Class factoryClass, T factory) { + Objects.requireNonNull(factory, "factory"); + factories.put(factoryClass, factory); + return this; + } + + public void registerDefaultFactories() { + registerFactory(Identity.Factory.class, new IdentityFactory()); + registerFactory(Position.Factory.class, new PositionFactory()); + registerFactory(Materials.Factory.class, new MaterialFactory()); + registerFactory(ItemStack.Factory.class, new ItemStackFactory()); + registerFactory(ToolMaterials.Factory.class, material -> { + switch (material) { + case "stone": + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.STONE); + case "iron": + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.IRON); + case "gold": + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.GOLD); + case "diamond": + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.DIAMOND); + case "netherite": + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.NETHERITE); + case "wood": + default: + return Wrappers.TOOL_MATERIAL.toSandbox(Tiers.WOOD); + } + }); + registerFactory(Attributes.BuiltinAttributeFactory.class, new AttributeFactory()); + registerFactory(Attribute.ModifierFactory.class, new AttributeModifierFactory()); + registerFactory(EventHandlerFactory.class, ResettableEventHandler::new); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementation.java b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementation.java new file mode 100644 index 0000000..a192607 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementation.java @@ -0,0 +1,19 @@ +package org.sandboxpowered.loader.inject; + +import com.google.inject.Inject; +import org.sandboxpowered.api.inject.FactoryProvider; +import org.sandboxpowered.api.inject.Implementation; + +public class SandboxImplementation implements Implementation { + private final FactoryProvider provider; + + @Inject + public SandboxImplementation(FactoryProvider provider) { + this.provider = provider; + } + + @Override + public FactoryProvider getFactoryProvider() { + return provider; + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementationModule.java b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementationModule.java new file mode 100644 index 0000000..9cb76ac --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/SandboxImplementationModule.java @@ -0,0 +1,32 @@ +package org.sandboxpowered.loader.inject; + +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.inject.FactoryProvider; +import org.sandboxpowered.api.inject.Implementation; +import org.sandboxpowered.api.inject.ImplementationModule; +import org.sandboxpowered.api.inject.Sandbox; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.sandboxpowered.loader.util.SandboxImpl; + +import javax.annotation.OverridingMethodsMustInvokeSuper; + +public class SandboxImplementationModule extends ImplementationModule { + @Override + @OverridingMethodsMustInvokeSuper + protected void configure() { + super.configure(); + + expose(SandboxPlatform.class); + + expose(FactoryProvider.class); + + bind(Logger.class).toInstance(SandboxImpl.LOGGER); + + bind(FactoryProvider.class).to(SandboxFactoryProvider.class); + bind(Implementation.class).to(SandboxImplementation.class); + + requestStaticInjection(Sandbox.class); + requestStaticInjection(Platform.class); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeFactory.java new file mode 100644 index 0000000..0497927 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeFactory.java @@ -0,0 +1,14 @@ +package org.sandboxpowered.loader.inject.factory; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import org.sandboxpowered.api.item.attribute.Attribute; +import org.sandboxpowered.api.item.attribute.Attributes; +import org.sandboxpowered.loader.Wrappers; + +public class AttributeFactory implements Attributes.BuiltinAttributeFactory { + @Override + public Attribute from(String id) { + return Wrappers.ATTRIBUTE.toSandbox(Registry.ATTRIBUTE.get(new ResourceLocation(id))); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeModifierFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeModifierFactory.java new file mode 100644 index 0000000..a11853c --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/AttributeModifierFactory.java @@ -0,0 +1,20 @@ +package org.sandboxpowered.loader.inject.factory; + +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.item.Item; +import org.sandboxpowered.api.item.attribute.Attribute; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.util.MojangUtil; + +import java.util.UUID; + +public class AttributeModifierFactory implements Attribute.ModifierFactory { + @Override + public Attribute.Modifier create(UUID attribute, String name, double value, Attribute.Operation operation) { + attribute = MojangUtil.checkMojangity(attribute, Item.BASE_ATTACK_DAMAGE_UUID); + attribute = MojangUtil.checkMojangity(attribute, Item.BASE_ATTACK_SPEED_UUID); + return Wrappers.ATTRIBUTE_MODIFIER.toSandbox(new AttributeModifier( + attribute, name, value, Wrappers.ATTRIBUTE_OPERATION.toVanilla(operation) + )); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/IdentityFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/IdentityFactory.java new file mode 100644 index 0000000..067411a --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/IdentityFactory.java @@ -0,0 +1,25 @@ +package org.sandboxpowered.loader.inject.factory; + +import net.minecraft.resources.ResourceLocation; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.Wrappers; + +public class IdentityFactory implements Identity.Factory { + @Override + public Identity create(String namespace, String path) { + return Wrappers.IDENTITY.toSandbox(new ResourceLocation(namespace, path)); + } + + @Override + public Identity create(String id) { + String[] identity = new String[]{"minecraft", id}; + int idx = id.indexOf(':'); + if (idx >= 0) { + identity[1] = id.substring(idx + 1); + if (idx >= 1) { + identity[0] = id.substring(0, idx); + } + } + return create(identity[0], identity[1]); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/ItemStackFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/ItemStackFactory.java new file mode 100644 index 0000000..6b4f3ef --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/ItemStackFactory.java @@ -0,0 +1,25 @@ +package org.sandboxpowered.loader.inject.factory; + +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.util.nbt.CompoundTag; +import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; +import org.sandboxpowered.loader.Wrappers; + +public class ItemStackFactory implements ItemStack.Factory { + @Override + public ItemStack create(Item item, int count, @Nullable CompoundTag nbt) { + if (count <= 0) + return Wrappers.ITEMSTACK.toSandbox(net.minecraft.world.item.ItemStack.EMPTY); + return Wrappers.ITEMSTACK.toSandbox(new net.minecraft.world.item.ItemStack( + Wrappers.ITEM.toVanilla(item), + count + )); + } + + @Override + public ItemStack fromTag(ReadableCompoundTag tag) { + return null; + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/MaterialFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/MaterialFactory.java new file mode 100644 index 0000000..6c9aa0d --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/MaterialFactory.java @@ -0,0 +1,111 @@ +package org.sandboxpowered.loader.inject.factory; + + +import org.sandboxpowered.api.block.Material; +import org.sandboxpowered.api.block.Materials; +import org.sandboxpowered.loader.Wrappers; + +public class MaterialFactory implements Materials.Factory { + + @Override + public Material get(String s) { + return Wrappers.MATERIAL.toSandbox(from(s)); + } + + public net.minecraft.world.level.material.Material from(String s) { + switch (s) { + case "AIR": + return net.minecraft.world.level.material.Material.AIR; + case "ANVIL": + case "REPAIR_STATION": + case "HEAVY_METAL": + return net.minecraft.world.level.material.Material.HEAVY_METAL; + case "METAL": + return net.minecraft.world.level.material.Material.METAL; + case "BAMBOO": + return net.minecraft.world.level.material.Material.BAMBOO; + case "BAMBOO_SAPLING": + return net.minecraft.world.level.material.Material.BAMBOO_SAPLING; + case "BARRIER": + return net.minecraft.world.level.material.Material.BARRIER; + case "BUBBLE_COLUMN": + return net.minecraft.world.level.material.Material.BUBBLE_COLUMN; + case "STONE": + return net.minecraft.world.level.material.Material.STONE; + case "LAVA": + return net.minecraft.world.level.material.Material.LAVA; + case "WATER": + return net.minecraft.world.level.material.Material.WATER; + case "UNDERWATER_PLANT": + return net.minecraft.world.level.material.Material.WATER_PLANT; + case "CACTUS": + return net.minecraft.world.level.material.Material.CACTUS; + case "CAKE": + return net.minecraft.world.level.material.Material.CAKE; + case "CARPET": + return net.minecraft.world.level.material.Material.CLOTH_DECORATION; + case "CLAY": + case "ORGANIC_PRODUCT": + return net.minecraft.world.level.material.Material.CLAY; + case "PISTON": + case "SUPPORTED": + case "PART": + return net.minecraft.world.level.material.Material.PISTON; + case "UNUSED_PLANT": + case "PLANT": + return net.minecraft.world.level.material.Material.PLANT; + case "TNT": + return net.minecraft.world.level.material.Material.EXPLOSIVE; + case "STRUCTURE_VOID": + return net.minecraft.world.level.material.Material.STRUCTURAL_AIR; + case "SNOW": + case "SNOW_LAYER": + return net.minecraft.world.level.material.Material.TOP_SNOW; + case "SNOW_BLOCK": + return net.minecraft.world.level.material.Material.SNOW; + case "COBWEB": + return net.minecraft.world.level.material.Material.WEB; + case "FIRE": + return net.minecraft.world.level.material.Material.FIRE; + case "SHULKER_BOX": + return net.minecraft.world.level.material.Material.SHULKER_SHELL; + case "AGGREGATE": + case "SAND": + return net.minecraft.world.level.material.Material.SAND; + case "ORGANIC": + case "PUMPKIN": + case "GOURD": + return net.minecraft.world.level.material.Material.VEGETABLE; + case "PORTAL": + return net.minecraft.world.level.material.Material.PORTAL; + case "REPLACEABLE_PLANT": + return net.minecraft.world.level.material.Material.REPLACEABLE_PLANT; + case "SEAGRASS": + case "REPLACEABLE_UNDERWATER_PLANT": + return net.minecraft.world.level.material.Material.REPLACEABLE_WATER_PLANT; + case "DENSE_ICE": + case "PACKED_ICE": + return net.minecraft.world.level.material.Material.ICE_SOLID; + case "EGG": + return net.minecraft.world.level.material.Material.EGG; + case "ICE": + return net.minecraft.world.level.material.Material.ICE; + case "EARTH": + case "SOIL": + return net.minecraft.world.level.material.Material.DIRT; + case "REDSTONE_LAMP": + return net.minecraft.world.level.material.Material.BUILDABLE_GLASS; + case "SPONGE": + return net.minecraft.world.level.material.Material.SPONGE; + case "WOOL": + return net.minecraft.world.level.material.Material.WOOL; + case "LEAVES": + return net.minecraft.world.level.material.Material.LEAVES; + case "GLASS": + return net.minecraft.world.level.material.Material.GLASS; + case "WOOD": + default: + return net.minecraft.world.level.material.Material.WOOD; + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/PositionFactory.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/PositionFactory.java new file mode 100644 index 0000000..6d345c2 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/PositionFactory.java @@ -0,0 +1,17 @@ +package org.sandboxpowered.loader.inject.factory; + +import net.minecraft.core.BlockPos; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.loader.Wrappers; + +public class PositionFactory implements Position.Factory{ + @Override + public Position immutable(int x, int y, int z) { + return Wrappers.POSITION.toSandbox(new BlockPos(x,y,z)); + } + + @Override + public Position.Mutable mutable(int x, int y, int z) { + return Wrappers.MUTABLE_POSITION.toSandbox(new BlockPos.MutableBlockPos(x,y,z)); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/factory/package-info.java b/common/src/main/java/org/sandboxpowered/loader/inject/factory/package-info.java new file mode 100644 index 0000000..d1a03a8 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/factory/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.inject.factory; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/inject/package-info.java b/common/src/main/java/org/sandboxpowered/loader/inject/package-info.java new file mode 100644 index 0000000..a5a16f0 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/inject/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.inject; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonClassLoader.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonClassLoader.java new file mode 100644 index 0000000..3706ec5 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonClassLoader.java @@ -0,0 +1,115 @@ +package org.sandboxpowered.loader.loading; + +import org.sandboxpowered.internal.AddonSpec; + +import java.io.ByteArrayOutputStream; +import java.io.FilePermission; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.CodeSource; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.SecureClassLoader; +import java.security.cert.Certificate; + +public class AddonClassLoader extends SecureClassLoader { + static { + registerAsParallelCapable(); + } + + private final SandboxLoader loader; + private final AddonSpec spec; + private final ClassLoader original; + private final URL url; + private final DynamicURLClassLoader classLoader = (DynamicURLClassLoader) getParent(); + private CodeSource addonSource; + + public AddonClassLoader(SandboxLoader loader, ClassLoader original, URL url, AddonSpec spec) { + super(new DynamicURLClassLoader(new URL[]{url}, original)); + this.loader = loader; + this.original = original; + this.spec = spec; + this.url = url; + } + + public CodeSource getAddonSource() { + if (addonSource == null) + addonSource = new CodeSource(url, (Certificate[]) null); + return addonSource; + } + + private byte[] readAddonClass(String name) throws IOException { + String classFile = name.replace('.', '/') + ".class"; + InputStream inputStream = classLoader.getResourceAsStream(classFile); + if (inputStream == null) { + return null; + } + + int a = inputStream.available(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(a < 32 ? 32768 : a); + byte[] buffer = new byte[8192]; + int len; + while ((len = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, len); + } + + inputStream.close(); + return outputStream.toByteArray(); + } + + private Class getLoadedOrDefineClass(String name) { + synchronized (getClassLoadingLock(name)) { + Class c = findLoadedClass(name); + + if (c != null || name.startsWith("java.")) return c; + + byte[] input = new byte[0]; + try { + input = readAddonClass(name); + } catch (IOException e) { + loader.log.error("Error reading addon class bytecode", e); + } + + if (input == null) return null; + + int delimiterIndex = name.lastIndexOf('.'); + if (delimiterIndex > 0) { + String classPackage = name.substring(0, delimiterIndex); + if (getPackage(classPackage) == null) + definePackage(classPackage, null, null, null, null, null, null, null); + } + + c = defineClass(name, input, 0, input.length, getAddonSource()); + return c; + } + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + Class c = getLoadedOrDefineClass(name); + if (c == null) c = original.loadClass(name); + if (resolve) resolveClass(c); + return c; + } + + @Override + protected PermissionCollection getPermissions(CodeSource codesource) { + Permissions pc = new Permissions(); + pc.add(new FilePermission("data/-", "read")); // Can read everything from data dir + pc.add(new FilePermission(String.format("data/%s/-", spec.getId()), "read,write,delete")); // Can write everything inside addon data dir + return pc; + } + + private static class DynamicURLClassLoader extends URLClassLoader { + static { + registerAsParallelCapable(); + } + + private DynamicURLClassLoader(URL[] urls, ClassLoader original) { + super(urls, null); + } + + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonFinder.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonFinder.java new file mode 100644 index 0000000..36db18d --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonFinder.java @@ -0,0 +1,99 @@ +package org.sandboxpowered.loader.loading; + +import com.google.common.collect.Sets; + +import java.io.IOException; +import java.net.JarURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public interface AddonFinder { + String SANDBOX_TOML = "sandbox.toml"; + + Collection findAddons() throws IOException; + + class MergedScanner implements AddonFinder { + private final Set finders; + + public MergedScanner(Set finders) { + this.finders = finders; + } + + public MergedScanner(AddonFinder... finders) { + this(Sets.newHashSet(finders)); + } + + public MergedScanner(AddonFinder finder) { + this(Collections.singleton(finder)); + } + + @Override + public Collection findAddons() throws IOException { + Set addons = new HashSet<>(); + for (AddonFinder finder : finders) { + addons.addAll(finder.findAddons()); + } + return addons; + } + } + + class FolderScanner implements AddonFinder { + private final Path addonPath; + + public FolderScanner(Path path) { + this.addonPath = path; + } + + @Override + public Collection findAddons() throws IOException { + if (Files.notExists(addonPath)) Files.createDirectories(addonPath); + try (Stream stream = Files.walk(addonPath, 1)) { + return stream.filter(path -> path.toString().endsWith(".jar")) + .map(path -> { + try { + return path.toUri().toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toSet()); + } + } + } + + class ClasspathScanner implements AddonFinder { + public static URL getSource(String filename, URL resourceURL) { + try { + URLConnection connection = resourceURL.openConnection(); + if (connection instanceof JarURLConnection) { + return ((JarURLConnection) connection).getJarFileURL(); + } else { + String path = resourceURL.getPath(); + if (!path.endsWith(filename)) { + throw new RuntimeException(String.format("Could not find code source for file '%s' and URL '%s'!", filename, resourceURL)); + } + + return new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), path.substring(0, path.length() - filename.length())); + } + } catch (Exception var5) { + throw new RuntimeException(var5); + } + } + + @Override + public Collection findAddons() throws IOException { + Set addons = new HashSet<>(); + Enumeration enumeration = getClass().getClassLoader().getResources(SANDBOX_TOML); + while (enumeration.hasMoreElements()) { + URL url = getSource(SANDBOX_TOML, enumeration.nextElement()); + addons.add(url); + } + return addons; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonLog.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonLog.java new file mode 100644 index 0000000..ab9f4c1 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonLog.java @@ -0,0 +1,51 @@ +package org.sandboxpowered.loader.loading; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.util.Log; +import org.sandboxpowered.internal.AddonSpec; + +public class AddonLog implements Log { + private final AddonSpec spec; + private final Logger logger; + + public AddonLog(AddonSpec spec) { + this.spec = spec; + this.logger = LogManager.getLogger(spec.getTitle()); + } + + @Override + public void info(String message) { + logger.info(message); + } + + @Override + public void error(String message) { + logger.error(message); + } + + @Override + public void debug(String message) { + logger.debug(message); + } + + @Override + public void info(String message, Object... args) { + logger.info(message, args); + } + + @Override + public void error(String message, Object... args) { + logger.error(message, args); + } + + @Override + public void debug(String message, Object... args) { + logger.debug(message, args); + } + + @Override + public void error(String message, Throwable e) { + logger.error(message, e); + } +} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonSecurityPolicy.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSecurityPolicy.java similarity index 96% rename from src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonSecurityPolicy.java rename to common/src/main/java/org/sandboxpowered/loader/loading/AddonSecurityPolicy.java index 544315b..d33db07 100644 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonSecurityPolicy.java +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSecurityPolicy.java @@ -1,4 +1,4 @@ -package org.sandboxpowered.sandbox.fabric.security; +package org.sandboxpowered.loader.loading; import java.security.*; @@ -49,4 +49,4 @@ private PermissionCollection applicationPermissions() { permissions.add(new AllPermission()); return permissions; } -} \ No newline at end of file +} diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificAPIReference.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificAPIReference.java new file mode 100644 index 0000000..b946849 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificAPIReference.java @@ -0,0 +1,55 @@ +package org.sandboxpowered.loader.loading; + +import org.sandboxpowered.api.SandboxAPI; +import org.sandboxpowered.api.addon.AddonInfo; +import org.sandboxpowered.api.util.Log; +import org.sandboxpowered.api.util.Side; +import org.sandboxpowered.internal.AddonSpec; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class AddonSpecificAPIReference implements SandboxAPI { + private final AddonSpec spec; + private final SandboxLoader loader; + private final Path configDir; + private Log log; + + public AddonSpecificAPIReference(AddonSpec spec, SandboxLoader loader) { + this.spec = spec; + this.loader = loader; + this.configDir = Paths.get("data", spec.getId()); + } + + @Override + public boolean isAddonLoaded(String addonId) { + return loader.isAddonLoaded(addonId); + } + + @Override + public boolean isExternalModLoaded(String loader, String modId) { + return this.loader.isExternalModLoaded(loader, modId); + } + + @Override + public AddonInfo getSourceAddon() { + return spec; + } + + @Override + public Side getSide() { + return loader.getSide(); + } + + @Override + public Path getConfigDirectory() { + return configDir; + } + + @Override + public Log getLog() { + if (log == null) + log = new AddonLog(spec); + return log; + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificRegistrarReference.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificRegistrarReference.java new file mode 100644 index 0000000..6c3178e --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificRegistrarReference.java @@ -0,0 +1,51 @@ +package org.sandboxpowered.loader.loading; + +import org.sandboxpowered.api.addon.AddonInfo; +import org.sandboxpowered.api.block.BaseBlock; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.BaseBlockItem; +import org.sandboxpowered.api.item.BlockItem; +import org.sandboxpowered.api.registry.Registrar; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.resources.ResourceService; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.internal.AddonSpec; + +import java.util.Optional; + +public class AddonSpecificRegistrarReference implements Registrar { + private final AddonSpec spec; + private final SandboxLoader loader; + + public AddonSpecificRegistrarReference(AddonSpec spec, SandboxLoader loader) { + this.spec = spec; + this.loader = loader; + } + + @Override + public AddonInfo getSourceAddon() { + return spec; + } + + @Override + public > Registry.Entry getEntry(Identity identity, Class tClass) { + return Registry.getRegistryFromType(tClass).get(identity); + } + + @Override + public > Registry.Entry getEntry(Identity identity, Registry registry) { + return registry.get(identity); + } + + @Override + public > Registry.Entry register(T content) { + return loader.register(content); + } + + @Override + public Optional getRegistrarService(Class tClass) { + if (tClass == ResourceService.class) + return Optional.of((T) loader.getResourceService().getServiceFor(getSourceAddon())); + return Optional.empty(); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificResourceRegistrar.java b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificResourceRegistrar.java new file mode 100644 index 0000000..8c8b160 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/AddonSpecificResourceRegistrar.java @@ -0,0 +1,49 @@ +package org.sandboxpowered.loader.loading; + +import org.sandboxpowered.api.addon.AddonInfo; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.resources.ResourceMaterial; +import org.sandboxpowered.api.resources.ResourceService; +import org.sandboxpowered.api.resources.ResourceType; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.internal.AddonSpec; +import org.sandboxpowered.loader.loading.resource_service.GlobalResourceService; + +import java.util.function.Supplier; + +public class AddonSpecificResourceRegistrar implements ResourceService { + private final AddonInfo spec; + private final GlobalResourceService resourceService; + + public AddonSpecificResourceRegistrar(AddonInfo spec, GlobalResourceService resourceService) { + this.spec = spec; + this.resourceService = resourceService; + } + + @Override + public void add(ResourceMaterial material, ResourceType... types) { + for (ResourceType type : types) { + add(material, type); + } + } + + @Override + public > void add(ResourceMaterial material, ResourceType type) { + add(material, type, type.createContent(material)); + } + + @Override + public > void add(ResourceMaterial material, ResourceType type, Supplier supplier) { + add(material, type, supplier.get()); + } + + @Override + public > void add(ResourceMaterial material, ResourceType type, C content) { + resourceService.add(material, type, content.setIdentity(Identity.of(spec.getId(), String.format("%s_%s", material.toString(), type.toString())))); + } + + @Override + public > boolean contains(ResourceMaterial material, ResourceType type) { + return resourceService.contains(material, type); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/SandboxLoader.java b/common/src/main/java/org/sandboxpowered/loader/loading/SandboxLoader.java new file mode 100644 index 0000000..6cd6d61 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/SandboxLoader.java @@ -0,0 +1,253 @@ +package org.sandboxpowered.loader.loading; + +import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.toml.TomlParser; +import com.github.zafarkhaja.semver.Parser; +import com.github.zafarkhaja.semver.expr.Expression; +import com.github.zafarkhaja.semver.expr.ExpressionParser; +import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import net.minecraft.client.Minecraft; +import net.minecraft.client.server.IntegratedServer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.storage.LevelResource; +import net.minecraft.world.level.storage.LevelStorageSource; +import org.apache.commons.io.IOUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.addon.Addon; +import org.sandboxpowered.api.block.BaseBlock; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.BaseBlockItem; +import org.sandboxpowered.api.item.BlockItem; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.api.util.Side; +import org.sandboxpowered.internal.AddonSpec; +import org.sandboxpowered.loader.loading.resource_service.GlobalResourceService; +import org.sandboxpowered.loader.packs.AddonPackRespositorySource; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Path; +import java.util.*; +import java.util.function.Consumer; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +import static org.sandboxpowered.loader.loading.AddonFinder.SANDBOX_TOML; + +public class SandboxLoader { + private static final Parser PARSER = ExpressionParser.newInstance(); + private final Map loadedAddons = new HashMap<>(); + private final Map addonMap = new HashMap<>(); + private final Map addonAPIs = new HashMap<>(); + private final Map addonRegistrars = new HashMap<>(); + private final Map addonToClassLoader = new LinkedHashMap<>(); + public Logger log = LogManager.getLogger(SandboxLoader.class); + public AddonPackRespositorySource addonPackRespositorySource = new AddonPackRespositorySource(); + private boolean loaded; + private final GlobalResourceService resourceService = new GlobalResourceService(); + + private AddonSpecificRegistrarReference getRegistrarForAddon(AddonSpec spec) { + return addonRegistrars.computeIfAbsent(spec, s -> new AddonSpecificRegistrarReference(s, this)); + } + + public GlobalResourceService getResourceService() { + return resourceService; + } + + private AddonSpecificAPIReference getAPIForAddon(AddonSpec spec) { + return addonAPIs.computeIfAbsent(spec, s -> new AddonSpecificAPIReference(s, this)); + } + + public Optional getAddon(String addonId) { + return Optional.ofNullable(loadedAddons.get(addonId)); + } + + public void loadAddon(AddonSpec info, Addon addon) { + loadedAddons.put(info.getId(), info); + addonMap.put(info, addon); + } + + private List getLoadOrder() { + Set visited = new HashSet<>(); + List loadOrder = new ArrayList<>(); + for (AddonSpec info : getAllAddons().keySet()) { + handleDependencies(visited, loadOrder, info); + } + return loadOrder; + } + + private void loopInOrder(Consumer consumer) { + getLoadOrder().forEach(spec -> { + if (!spec.getPlatformSupport(getPlatform()).canRun()) { + throw new IllegalStateException(String.format("Addon %s cannot run on platform %s!", spec.getId(), getPlatform().toString())); + } + try { + consumer.accept(spec); + } catch (Exception e) { + throw new RuntimeException(String.format("Loading for addon %s failed: %s", spec.getId(), e.getMessage()), e); + } + }); + } + + public Identity getPlatform() { + return Identity.of("sandbox", "test"); + } + + private void handleDependencies(Set visited, List order, AddonSpec spec) { + if (visited.contains(spec)) return; + visited.add(spec); + Map dependencies = spec.getDependencies(); + for (String dep : dependencies.keySet()) { + Optional optionalDep = getAddon(dep); + if (!optionalDep.isPresent()) + throw new IllegalStateException(String.format("Addon %s depends on other addon %s that isn't loaded!", spec.getId(), dep)); + AddonSpec dependency = optionalDep.get(); + String versionString = dependencies.get(dep); + Expression version = PARSER.parse(versionString); + if (!version.interpret(dependency.getVersion())) + throw new IllegalStateException(String.format("Addon %s depends on %s version %s but found version %s instead!", spec.getId(), dep, versionString, dependency.getVersion().toString())); + handleDependencies(visited, order, dependency); + } + order.add(spec); + } + + public Map getAllAddons() { + return ImmutableMap.copyOf(addonMap); + } + + public void unload() { + log.info("Unloading Sandbox"); + resourceService.clear(); + loadedAddons.clear(); + addonMap.clear(); + addonAPIs.clear(); + addonRegistrars.clear(); + addonToClassLoader.clear(); + loaded = false; + } + + public AddonClassLoader getClassLoader(AddonSpec spec, URL url) { + return addonToClassLoader.computeIfAbsent(spec.getId(), addonId -> new AddonClassLoader(this, Addon.class.getClassLoader(), url, spec)); + } + + private void loadFromURLs(Collection urls) { + if (urls.isEmpty()) { + log.info("Loaded 0 addons"); + } else { + log.info("Loading {} addons", urls.size()); + TomlParser parser = new TomlParser(); + for (URL url : urls) { + InputStream configStream = null; + JarFile jarFile = null; + try { + if (url.toString().endsWith(".jar")) { + jarFile = new JarFile(new File(url.toURI())); + ZipEntry ze = jarFile.getEntry(SANDBOX_TOML); + if (ze != null) + configStream = jarFile.getInputStream(ze); + } else { + configStream = url.toURI().resolve(SANDBOX_TOML).toURL().openStream(); + } + if (configStream == null) + continue; + Config config = parser.parse(configStream); + AddonSpec spec = AddonSpec.from(config, url); + AddonClassLoader loader = getClassLoader(spec, url); + Class mainClass = loader.loadClass(spec.getMainClass()); + Object obj = mainClass.getConstructor().newInstance(); + if (obj instanceof Addon) { + loadAddon(spec, (Addon) obj); + } else { + log.error("Unable to load addon '{}', main class not instance of Addon", spec.getId()); + } + } catch (IOException | NoSuchMethodException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | URISyntaxException e) { + log.error("Unknown Error", e); + //TODO: Split these up to provide unique messages per error. + } finally { + IOUtils.closeQuietly(configStream); + IOUtils.closeQuietly(jarFile); + } + } + } + } + + public void load(MinecraftServer server, LevelStorageSource.LevelStorageAccess storageSource) { + Path path = storageSource.getLevelPath(LevelResource.ROOT); + Path addonsDir = path.resolve("addons"); + AddonFinder finder = new AddonFinder.MergedScanner( + new AddonFinder.FolderScanner(addonsDir), + new AddonFinder.ClasspathScanner() + ); + try { + loadFromURLs(finder.findAddons()); + } catch (IOException e) { + log.error("Failed to load classpath addons", e); + } + + resourceService.initVanillaContent(); + + loopInOrder(spec -> addonMap.get(spec).init(getAPIForAddon(spec))); + loopInOrder(spec -> addonMap.get(spec).register(getAPIForAddon(spec), getRegistrarForAddon(spec))); + loopInOrder(spec -> addonMap.get(spec).finishLoad(getAPIForAddon(spec))); + loaded = true; + + resourceService.getResourceMap().forEach((material, subMap) -> subMap.forEach((type, resource) -> { + Content o = resource.get(); + Set set = resource.getVariants(); + if (o != null) { + if (o.getIdentity().getNamespace().equals("minecraft")) { + if (set.size() > 1) { + log.info(String.format("Ignoring %d variants for '%s:%s' as '%s' already exists.", set.size() - 1, material, type, o.getIdentity())); + } + } else { + register(o); + } + } + })); + + if (server instanceof IntegratedServer) { + reloadClientResources(); + } + server.getPackRepository().reload(); + server.reloadResources(server.getPackRepository().getSelectedIds()); + } + + @CanIgnoreReturnValue + public > Registry.Entry register(C content) { + Registry.Entry entry = Registry.getRegistryFromType(content.getContentType()).register(content); + if (content instanceof BaseBlock) { + BlockItem item = ((BaseBlock) content).createBlockItem(); + if (item instanceof BaseBlockItem) { + Registry.getRegistryFromType(item.getContentType()).register(item.setIdentity(content.getIdentity())); + } + } + return entry; + } + + private void reloadClientResources() { + Minecraft.getInstance().reloadResourcePacks(); + } + + public boolean isAddonLoaded(String addonId) { + return getAddon(addonId).isPresent(); + } + + public Side getSide() { + return Side.SERVER; + } + + public boolean isExternalModLoaded(String loader, String modId) { + return false; + } + + public boolean isLoaded() { + return loaded; + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/package-info.java b/common/src/main/java/org/sandboxpowered/loader/loading/package-info.java new file mode 100644 index 0000000..b0a4cc6 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.loading; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/GlobalResourceService.java b/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/GlobalResourceService.java new file mode 100644 index 0000000..aaab9d2 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/GlobalResourceService.java @@ -0,0 +1,126 @@ +package org.sandboxpowered.loader.loading.resource_service; + +import org.sandboxpowered.api.addon.AddonInfo; +import org.sandboxpowered.api.block.Blocks; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.Items; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.resources.ResourceConstants; +import org.sandboxpowered.api.resources.ResourceMaterial; +import org.sandboxpowered.api.resources.ResourceService; +import org.sandboxpowered.api.resources.ResourceType; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.loading.AddonSpecificResourceRegistrar; + +import java.util.*; + +import static org.sandboxpowered.api.resources.ResourceConstants.*; +import static org.sandboxpowered.api.resources.ResourceConstants.DUST; +import static org.sandboxpowered.api.resources.ResourceConstants.GEM; + +public class GlobalResourceService { + private final Map serviceMap = new LinkedHashMap<>(); + private final Map, ResourceImpl>> resourceMap = new IdentityHashMap<>(); + private final PrioritySortOrder sortOrder = new PrioritySortOrder(); + + public void initVanillaContent() { + add(IRON, INGOT, Items.IRON_INGOT); + add(IRON, NUGGET, Items.IRON_NUGGET); + add(IRON, ORE, Blocks.IRON_ORE); + add(IRON, BLOCK, Blocks.IRON_BLOCK); + + add(GOLD, INGOT, Items.GOLD_INGOT); + add(GOLD, NUGGET, Items.GOLD_NUGGET); + add(GOLD, ORE, Blocks.GOLD_ORE); + add(GOLD, NETHER_ORE, Blocks.NETHER_GOLD_ORE); + add(GOLD, BLOCK, Blocks.GOLD_BLOCK); + + add(DIAMOND, GEM, Items.DIAMOND); + add(DIAMOND, ORE, Blocks.DIAMOND_ORE); + add(DIAMOND, BLOCK, Blocks.DIAMOND_BLOCK); + + add(EMERALD, GEM, Items.EMERALD); + add(EMERALD, ORE, Blocks.EMERALD_ORE); + add(EMERALD, BLOCK, Blocks.EMERALD_BLOCK); + + add(GLOWSTONE, DUST, Items.GLOWSTONE_DUST); + add(GLOWSTONE, BLOCK, Blocks.GLOWSTONE); + + add(COAL, GEM, Items.COAL); + add(COAL, ORE, Blocks.COAL_ORE); + add(COAL, BLOCK, Blocks.COAL_BLOCK); + + add(OBSIDIAN, BLOCK, Blocks.OBSIDIAN); + + add(NETHERITE, INGOT, Items.NETHERITE_INGOT); + add(NETHERITE, SCRAP, Items.NETHERITE_SCRAP); + add(NETHERITE, NETHER_ORE, Blocks.ANCIENT_DEBRIS); + add(NETHERITE, BLOCK, Blocks.NETHERITE_BLOCK); + + add(REDSTONE, DUST, Items.REDSTONE); + add(REDSTONE, ORE, Blocks.REDSTONE_ORE); + add(REDSTONE, BLOCK, Blocks.REDSTONE_BLOCK); + + add(LAPIS, GEM, Items.LAPIS_LAZULI); + add(LAPIS, ORE, Blocks.LAPIS_ORE); + add(LAPIS, BLOCK, Blocks.LAPIS_BLOCK); + + add(QUARTZ, GEM, Items.QUARTZ); + add(QUARTZ, NETHER_ORE, Blocks.NETHER_QUARTZ_ORE); + add(QUARTZ, BLOCK, Blocks.QUARTZ_BLOCK); + } + + public void clear() { + resourceMap.clear(); + serviceMap.clear(); + } + + public ResourceService getServiceFor(AddonInfo info) { + return serviceMap.computeIfAbsent(info, i -> new AddonSpecificResourceRegistrar(info, this)); + } + + public Map, ResourceImpl>> getResourceMap() { + return resourceMap; + } + + public > void add(ResourceMaterial material, ResourceType type, Registry.Entry variant) { + add(material, type, variant.get()); + } + + public > void add(ResourceMaterial material, ResourceType type, C variant) { + Map, ResourceImpl> map = resourceMap.computeIfAbsent(material, t -> new IdentityHashMap<>()); + ResourceImpl resource = (ResourceImpl) map.computeIfAbsent(type, t -> new ResourceImpl<>(material, type, sortOrder)); + resource.addVariant(variant); + } + + public > boolean contains(ResourceMaterial material, ResourceType type) { + Map, ResourceImpl> map = resourceMap.get(material); + return map != null && map.containsKey(type); + } + + public > ResourceImpl getResource(ResourceMaterial material, ResourceType type) { + if (!resourceMap.containsKey(material)) + return null; + ResourceImpl resource = (ResourceImpl) resourceMap.get(material).get(type); + return resource; + } + + public static class PrioritySortOrder implements Comparator> { + private static int getPriority(String namespace, List namespaces) { + int priority = namespaces.indexOf(namespace); + return priority == -1 ? Integer.MAX_VALUE : priority; + } + + @Override + public int compare(Content o1, Content o2) { + Identity id1 = o1.getIdentity(); + Identity id2 = o2.getIdentity(); + List namespaces = Collections.singletonList("minecraft"); + int comparison = Integer.compare( + getPriority(id1.getNamespace(), namespaces), + getPriority(id2.getNamespace(), namespaces) + ); + return comparison != 0 ? comparison : id1.toString().compareTo(id2.toString()); + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/ResourceImpl.java b/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/ResourceImpl.java new file mode 100644 index 0000000..1d7a503 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/loading/resource_service/ResourceImpl.java @@ -0,0 +1,49 @@ +package org.sandboxpowered.loader.loading.resource_service; + +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.resources.Resource; +import org.sandboxpowered.api.resources.ResourceMaterial; +import org.sandboxpowered.api.resources.ResourceType; + +import java.util.*; + +public class ResourceImpl> implements Resource { + private final SortedSet variants; + private final ResourceMaterial resourceMaterial; + private final ResourceType form; + + public ResourceImpl(ResourceMaterial resourceMaterial, ResourceType form, Comparator> comparator) { + this.variants = new TreeSet<>(comparator); + this.resourceMaterial = resourceMaterial; + this.form = form; + } + + @Override + public C get() { + return variants.first(); + } + + @Override + public Set getVariants() { + return Collections.unmodifiableSet(variants); + } + + @Override + public ResourceMaterial getMaterial() { + return resourceMaterial; + } + + @Override + public ResourceType getType() { + return form; + } + + @Override + public String toString() { + return String.format("Resource %s %s: %s", getMaterial(), getType(), get()); + } + + public void addVariant(C variant) { + variants.add(variant); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/ecs/be/MixinBlockEntity.java b/common/src/main/java/org/sandboxpowered/loader/mixin/ecs/be/MixinBlockEntity.java new file mode 100644 index 0000000..215d88e --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/ecs/be/MixinBlockEntity.java @@ -0,0 +1,11 @@ +package org.sandboxpowered.loader.mixin.ecs.be; + +import net.minecraft.world.level.block.entity.BlockEntity; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(BlockEntity.class) +public class MixinBlockEntity { + private static int totalEntities = 0; + + private final int sandbox_ecsId = totalEntities++; +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinMultiPlayerGameMode.java b/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinMultiPlayerGameMode.java new file mode 100644 index 0000000..fb401f3 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinMultiPlayerGameMode.java @@ -0,0 +1,67 @@ +package org.sandboxpowered.loader.mixin.event.network; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.sandboxpowered.api.util.Hand; +import org.sandboxpowered.api.events.BlockEvents; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.util.InteractionResult; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.eventhandler.Cancellable; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(MultiPlayerGameMode.class) +public class MixinMultiPlayerGameMode { + + @Shadow + @Final + private Minecraft minecraft; + + @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) + public void tryBreakBlock(BlockPos pos, CallbackInfoReturnable info) { + Level level = minecraft.level; + if (BlockEvents.BREAK.hasSubscribers()) { + Cancellable cancellable = new Cancellable(); + World world = Wrappers.WORLD.toSandbox(level); + Position position = Wrappers.POSITION.toSandbox(pos); + BlockState state = world.getBlockState(position); + ItemStack tool = ItemStack.empty(); + + BlockEvents.BREAK.post(breakEvent -> breakEvent.onEvent(world, position, state, null, tool, cancellable), cancellable); + if (cancellable.isCancelled()) { + info.setReturnValue(false); + } + } + } + + @Inject(method = "useItemOn", at = @At(value = "HEAD"), cancellable = true) + public void interactBlock(LocalPlayer localPlayer, ClientLevel clientLevel, InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable info) { + if (BlockEvents.INTERACT.hasSubscribers()) { + World world = Wrappers.WORLD.toSandbox(clientLevel); + Position position = Wrappers.POSITION.toSandbox(blockHitResult.getBlockPos()); + BlockState blockstate = world.getBlockState(position); + ItemStack tool = ItemStack.empty(); + Hand sandHand = interactionHand == InteractionHand.MAIN_HAND ? Hand.MAIN_HAND : Hand.OFF_HAND; + + InteractionResult result = BlockEvents.INTERACT.post((event, res) -> event.onEvent(world, position, blockstate, null, sandHand, tool, res), InteractionResult.IGNORE); + + if (result != InteractionResult.IGNORE) { + info.setReturnValue(Wrappers.INTERACTION_RESULT.toVanilla(result)); + } + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinServerPlayerGameMode.java b/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinServerPlayerGameMode.java new file mode 100644 index 0000000..b4802c5 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/event/network/MixinServerPlayerGameMode.java @@ -0,0 +1,62 @@ +package org.sandboxpowered.loader.mixin.event.network; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.sandboxpowered.api.util.Hand; +import org.sandboxpowered.api.events.BlockEvents; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.util.InteractionResult; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.eventhandler.Cancellable; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ServerPlayerGameMode.class) +public class MixinServerPlayerGameMode { + @Shadow + public ServerLevel level; + + @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) + public void tryBreakBlock(BlockPos pos, CallbackInfoReturnable info) { + if (BlockEvents.BREAK.hasSubscribers()) { + Cancellable cancellable = new Cancellable(); + World world = Wrappers.WORLD.toSandbox(level); + Position position = Wrappers.POSITION.toSandbox(pos); + BlockState state = world.getBlockState(position); + ItemStack tool = ItemStack.empty(); + + BlockEvents.BREAK.post(breakEvent -> breakEvent.onEvent(world, position, state, null, tool, cancellable), cancellable); + if (cancellable.isCancelled()) { + info.setReturnValue(false); + } + } + } + + @Inject(method = "useItemOn", at = @At(value = "HEAD"), cancellable = true) + public void interactBlock(ServerPlayer serverPlayer, Level level, net.minecraft.world.item.ItemStack itemStack, InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable info) { + if (BlockEvents.INTERACT.hasSubscribers()) { + World world = Wrappers.WORLD.toSandbox(level); + Position position = Wrappers.POSITION.toSandbox(blockHitResult.getBlockPos()); + BlockState blockstate = world.getBlockState(position); + ItemStack tool = ItemStack.empty(); + Hand sandHand = interactionHand == InteractionHand.MAIN_HAND ? Hand.MAIN_HAND : Hand.OFF_HAND; + + InteractionResult result = BlockEvents.INTERACT.post((event, res) -> event.onEvent(world, position, blockstate, null, sandHand, tool, res), InteractionResult.IGNORE); + + if (result != InteractionResult.IGNORE) { + info.setReturnValue(Wrappers.INTERACTION_RESULT.toVanilla(result)); + } + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/enchantment_acceptable_item/MixinEnchantmentHelper.java b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/enchantment_acceptable_item/MixinEnchantmentHelper.java new file mode 100644 index 0000000..1457205 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/enchantment_acceptable_item/MixinEnchantmentHelper.java @@ -0,0 +1,40 @@ +package org.sandboxpowered.loader.mixin.fixes.enchantment_acceptable_item; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentCategory; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.EnchantmentInstance; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Iterator; +import java.util.List; + +/** + * Fixes EnchantmentHelper bypassing Enchantment#canEnchant + */ +@Mixin(EnchantmentHelper.class) +public class MixinEnchantmentHelper { + private static final ThreadLocal ENCHANTMENT_THREAD_LOCAL = new ThreadLocal<>(); + + @Inject(method = "getAvailableEnchantmentResults", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/Enchantment;isTreasureOnly()Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private static void localEnchantment(int power, ItemStack stack, boolean allowTreasure, CallbackInfoReturnable info, List ret, Item item, boolean isBook, Iterator itr, Enchantment enchantment) { + ENCHANTMENT_THREAD_LOCAL.set(enchantment); + } + + @Redirect(method = "getAvailableEnchantmentResults", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;canEnchant(Lnet/minecraft/world/item/Item;)Z")) + private static boolean isAcceptableItem(EnchantmentCategory target, Item item, int i, ItemStack itemStack, boolean bl) { + Enchantment enchantment = ENCHANTMENT_THREAD_LOCAL.get(); + ENCHANTMENT_THREAD_LOCAL.remove(); + if (enchantment == null) { + return target.canEnchant(item); + } + return enchantment.canEnchant(itemStack); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/recipe_caching/MixinAbstractFurnaceBlockEntity.java b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/recipe_caching/MixinAbstractFurnaceBlockEntity.java new file mode 100644 index 0000000..bc22625 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/recipe_caching/MixinAbstractFurnaceBlockEntity.java @@ -0,0 +1,51 @@ +package org.sandboxpowered.loader.mixin.fixes.recipe_caching; + +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Optional; + +@Mixin(AbstractFurnaceBlockEntity.class) +public abstract class MixinAbstractFurnaceBlockEntity extends BaseContainerBlockEntity { + @Shadow + public abstract ItemStack getItem(int i); + + public MixinAbstractFurnaceBlockEntity(BlockEntityType blockEntityType) { + super(blockEntityType); + } + + private AbstractCookingRecipe cachedRecipe = null; + private ItemStack noRecipeStack = null; + + /** + * @reason Improves speed of furnace by caching the recipe until the input becomes invalid for the recipe + */ + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/crafting/RecipeManager;getRecipeFor(Lnet/minecraft/world/item/crafting/RecipeType;Lnet/minecraft/world/Container;Lnet/minecraft/world/level/Level;)Ljava/util/Optional;")) + private Optional getCachedRecipe(RecipeManager manager, RecipeType recipeType, C container, Level level) { + ItemStack input = getItem(0); + if (input.isEmpty() || input == noRecipeStack) { + return Optional.empty(); + } + + if (cachedRecipe != null && cachedRecipe.matches(container, level)) { + return Optional.of(cachedRecipe); + } else { + AbstractCookingRecipe rec = manager.getRecipeFor(recipeType, container, level).orElse(null); + if (rec == null) noRecipeStack = input; + else noRecipeStack = null; + cachedRecipe = rec; + return Optional.ofNullable(rec); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinBee.java b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinBee.java new file mode 100644 index 0000000..18b4417 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinBee.java @@ -0,0 +1,32 @@ +package org.sandboxpowered.loader.mixin.fixes.spawner_rendering; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.NeutralMob; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.Bee; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Bee.class) +public abstract class MixinBee extends Animal implements NeutralMob { + public MixinBee(EntityType entityType, Level level) { + super(entityType, level); + } + + /** + * Fixes MC-189565 + */ + @Inject(method = "readAdditionalSaveData", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/animal/Bee;numCropsGrownSincePollination:I", shift = At.Shift.AFTER), cancellable = true) + private void worldCheckAngerFromTag(CompoundTag tag, CallbackInfo ci) { + if (!this.level.isClientSide) { + this.readPersistentAngerSaveData((ServerLevel) level, tag); + } + + ci.cancel(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinEnderMan.java b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinEnderMan.java new file mode 100644 index 0000000..1ec50f3 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/fixes/spawner_rendering/MixinEnderMan.java @@ -0,0 +1,32 @@ +package org.sandboxpowered.loader.mixin.fixes.spawner_rendering; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.NeutralMob; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EnderMan.class) +public abstract class MixinEnderMan extends Monster implements NeutralMob { + public MixinEnderMan(EntityType entityType, Level level) { + super(entityType, level); + } + + /** + * Fixes MC-189565 + */ + @Inject(method = "readAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/EnderMan;setCarriedBlock(Lnet/minecraft/world/level/block/state/BlockState;)V", shift = At.Shift.AFTER), cancellable = true) + private void worldCheckAngerFromTag(CompoundTag tag, CallbackInfo ci) { + if (!this.level.isClientSide) { + this.readPersistentAngerSaveData((ServerLevel) level, tag); + } + + ci.cancel(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinEnchantmentCategory.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinEnchantmentCategory.java new file mode 100644 index 0000000..fe98fc9 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinEnchantmentCategory.java @@ -0,0 +1,24 @@ +package org.sandboxpowered.loader.mixin.injection; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.enchantment.EnchantmentCategory; +import org.sandboxpowered.api.item.tool.ToolItem; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(EnchantmentCategory.class) +public class MixinEnchantmentCategory { + + @Mixin(targets = "net.minecraft.world.item.enchantment.EnchantmentCategory$7") + public static class MixinDiggerCategory { + @Inject(method = "canEnchant", at = @At("HEAD"), cancellable = true) + public void canEnchant(Item item, CallbackInfoReturnable info) { + org.sandboxpowered.api.item.Item sandbox = Wrappers.ITEM.toSandbox(item); + if (sandbox instanceof ToolItem) + info.setReturnValue(true); + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinResourceLocation.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinResourceLocation.java new file mode 100644 index 0000000..5788b52 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/MixinResourceLocation.java @@ -0,0 +1,26 @@ +package org.sandboxpowered.loader.mixin.injection; + +import net.minecraft.resources.ResourceLocation; +import org.sandboxpowered.api.util.Identity; +import org.spongepowered.asm.mixin.*; + +@Mixin(ResourceLocation.class) +@Implements(@Interface(iface = Identity.class, prefix = "identity$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinResourceLocation { + @Shadow + @Final + protected String path; + + @Shadow + @Final + protected String namespace; + + public String identity$getNamespace() { + return namespace; + } + + public String identity$getPath() { + return path; + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinBlock.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinBlock.java new file mode 100644 index 0000000..1d57de8 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinBlock.java @@ -0,0 +1,69 @@ +package org.sandboxpowered.loader.mixin.injection.block; + +import net.minecraft.core.Registry; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.state.BlockBehaviour; +import org.jetbrains.annotations.NotNull; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.item.tool.ToolType; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.wrapper.IVanillaBlock; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import java.util.Collections; +import java.util.List; + +@Mixin(net.minecraft.world.level.block.Block.class) +@Implements(@Interface(iface = Block.class, prefix = "block$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinBlock extends BlockBehaviour implements IVanillaBlock { + private int sandbox_harvestLevel = -1; + private ToolType sandbox_toolType; + + public MixinBlock(Properties properties) { + super(properties); + } + + @NotNull + public List block$getDrops(@NotNull World world, @NotNull Position position, @NotNull BlockState state) { + if (!(world instanceof ServerLevel)) + return Collections.emptyList(); + return (List) (Object) net.minecraft.world.level.block.Block.getDrops( + Wrappers.BLOCKSTATE.toVanilla(state), + (ServerLevel) world, + Wrappers.POSITION.toVanilla(position), + null + ); + } + + public @NotNull Identity block$getIdentity() { + return Wrappers.IDENTITY.toSandbox( Registry.BLOCK.getKey((net.minecraft.world.level.block.Block) (Object) this)); + } + + + public int block$getHarvestLevel(@NotNull BlockState state) { + return sandbox_harvestLevel; + } + + public ToolType block$getHarvestTool(@NotNull BlockState state) { + return sandbox_toolType; + } + + @Override + public void sandbox_setHarvestParams(@NotNull ToolType type, int harvestLevel) { + sandbox_toolType = type; + sandbox_harvestLevel = harvestLevel; + } + + public boolean block$doesRequireCorrectToolForDrops(@NotNull BlockState state) { + return Wrappers.BLOCKSTATE.toVanilla(state).requiresCorrectToolForDrops(); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinCropBlock.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinCropBlock.java new file mode 100644 index 0000000..288c25d --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinCropBlock.java @@ -0,0 +1,41 @@ +package org.sandboxpowered.loader.mixin.injection.block; + +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.CropBlock; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.*; + +@Mixin(CropBlock.class) +@Implements(@Interface(iface = org.sandboxpowered.api.block.CropBlock.class, prefix = "crop$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinCropBlock { + @Shadow + public abstract net.minecraft.world.level.block.state.BlockState getStateForAge(int i); + + @Shadow + public abstract int getMaxAge(); + + @Shadow + protected abstract int getAge(net.minecraft.world.level.block.state.BlockState blockState); + + @Shadow + protected abstract ItemLike getBaseSeedId(); + + public Item crop$getSeed() { + return Wrappers.ITEM.toSandbox(getBaseSeedId().asItem()); + } + + public int crop$getAge(BlockState state) { + return getAge(Wrappers.BLOCKSTATE.toVanilla(state)); + } + + public int crop$getMaxAge() { + return getMaxAge(); + } + + public BlockState crop$stateForAge(int age) { + return Wrappers.BLOCKSTATE.toSandbox(getStateForAge(age)); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinMaterial.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinMaterial.java new file mode 100644 index 0000000..04f0610 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/block/MixinMaterial.java @@ -0,0 +1,55 @@ +package org.sandboxpowered.loader.mixin.injection.block; + +import net.minecraft.world.level.material.Material; +import org.spongepowered.asm.mixin.*; + +@Mixin(Material.class) +@Implements(@Interface(iface = org.sandboxpowered.api.block.Material.class, prefix = "mat$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinMaterial { + + @Shadow public abstract boolean blocksMotion(); + + @Shadow public abstract boolean isFlammable(); + + @Shadow public abstract boolean isLiquid(); + + @Shadow public abstract boolean isSolidBlocking(); + + @Shadow public abstract boolean isReplaceable(); + + @Shadow public abstract boolean isSolid(); + + public org.sandboxpowered.api.block.Material.PistonInteraction mat$getPistonInteraction() { + return org.sandboxpowered.api.block.Material.PistonInteraction.IGNORE; + } + + public boolean mat$doesBlockMovement() { + return blocksMotion(); + } + + public boolean mat$isBurnable() { + return isFlammable(); + } + + //TODO figure out which method this is supposed to be + public boolean mat$isBreakByHand() { + return false; + } + + public boolean mat$isLiquid() { + return this.isLiquid(); + } + + public boolean mat$doesBlockLight() { + return this.isSolidBlocking(); + } + + public boolean mat$isReplaceable() { + return this.isReplaceable(); + } + + public boolean mat$isSolid() { + return this.isSolid(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/blockstate/MixinBlockState.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/blockstate/MixinBlockState.java new file mode 100644 index 0000000..2c7c922 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/blockstate/MixinBlockState.java @@ -0,0 +1,35 @@ +package org.sandboxpowered.loader.mixin.injection.blockstate; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.state.BlockBehaviour; +import org.jetbrains.annotations.NotNull; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.*; + +@Mixin(BlockBehaviour.BlockStateBase.class) +@Implements(@Interface(iface = BlockState.class, prefix = "state$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinBlockState { + @Shadow + public abstract net.minecraft.world.level.block.Block getBlock(); + + @Shadow + public abstract float getDestroySpeed(BlockGetter blockGetter, BlockPos blockPos); + + @NotNull + public Block state$getBlock() { + return Wrappers.BLOCK.toSandbox(getBlock()); + } + + public float state$getDestroySpeed(@NotNull World world,@NotNull Position position) { + return getDestroySpeed( + Wrappers.WORLD.toVanilla(world), + Wrappers.POSITION.toVanilla(position) + ); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinClientPackSource.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinClientPackSource.java new file mode 100644 index 0000000..55d4f15 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinClientPackSource.java @@ -0,0 +1,26 @@ +package org.sandboxpowered.loader.mixin.injection.experimental; + +import net.minecraft.client.resources.ClientPackSource; +import net.minecraft.server.packs.repository.Pack; +import org.sandboxpowered.loader.loading.SandboxLoader; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Consumer; + +@Mixin(ClientPackSource.class) +public class MixinClientPackSource { + @Inject(method = "loadPacks", at = @At("HEAD")) + public void load(Consumer consumer, Pack.PackConstructor packConstructor, CallbackInfo ci) { + SandboxPlatform platform = Platform.getPlatform(); + if(platform.isLoaded()) { + SandboxLoader loader = platform.getLoader(); + + loader.addonPackRespositorySource.loadPacks(consumer, packConstructor); + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinServerPacksSource.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinServerPacksSource.java new file mode 100644 index 0000000..7d7be29 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/experimental/MixinServerPacksSource.java @@ -0,0 +1,26 @@ +package org.sandboxpowered.loader.mixin.injection.experimental; + +import net.minecraft.server.packs.repository.Pack; +import net.minecraft.server.packs.repository.ServerPacksSource; +import org.sandboxpowered.loader.loading.SandboxLoader; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Consumer; + +@Mixin(ServerPacksSource.class) +public class MixinServerPacksSource { + @Inject(method = "loadPacks", at = @At("HEAD")) + public void load(Consumer consumer, Pack.PackConstructor packConstructor, CallbackInfo ci) { + SandboxPlatform platform = Platform.getPlatform(); + if(platform.isLoaded()) { + SandboxLoader loader = platform.getLoader(); + + loader.addonPackRespositorySource.loadPacks(consumer, packConstructor); + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItem.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItem.java new file mode 100644 index 0000000..c14bcd1 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItem.java @@ -0,0 +1,31 @@ +package org.sandboxpowered.loader.mixin.injection.item; + +import net.minecraft.core.Registry; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(net.minecraft.world.item.Item.class) +@Implements(@Interface(iface = Item.class, prefix = "item$", remap = Interface.Remap.NONE)) +@Unique +public class MixinItem implements Content { + @Override + public Class getContentType() { + return Item.class; + } + + @Override + public Identity getIdentity() { + return Wrappers.IDENTITY.toSandbox(Registry.ITEM.getKey(net.minecraft.world.item.Item.class.cast(this))); + } + + @Override + public Item setIdentity(Identity identity) { + throw new RuntimeException(); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemRenderer.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemRenderer.java new file mode 100644 index 0000000..123d877 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemRenderer.java @@ -0,0 +1,68 @@ +package org.sandboxpowered.loader.mixin.injection.item; + +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.world.item.ItemStack; +import org.sandboxpowered.api.events.ItemEvents; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ItemRenderer.class) +public class MixinItemRenderer { + + private final ThreadLocal stackThreadLocal = new ThreadLocal<>(); + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isDamaged()Z")) + public boolean shouldRenderBar(ItemStack itemStack) { + org.sandboxpowered.api.item.ItemStack sbxStack = stackThreadLocal.get(); + Item item = sbxStack.getItem(); + if (ItemEvents.SHOW_DURABILITY_BAR.hasSubscribers()) + return ItemEvents.SHOW_DURABILITY_BAR.post((event, show) -> event.onEvent(sbxStack, show), item.showDurabilityBar(sbxStack)); + return item.showDurabilityBar(sbxStack); + } + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getMaxDamage()I")) + public int maxDamage(ItemStack itemStack) { + if (itemStack.getMaxDamage() == 0) + return 1; + return itemStack.getMaxDamage(); + } + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getDamageValue()I")) + public int damageValue(ItemStack itemStack) { + if (itemStack.getMaxDamage() == 0) + return 0; + return itemStack.getDamageValue(); + } + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Ljava/lang/Math;round(F)I")) + public int damageFloat(float v) { + org.sandboxpowered.api.item.ItemStack stack = stackThreadLocal.get(); + if (ItemEvents.GET_DURABILITY_VALUE.hasSubscribers()) { + float value = stack.getItem().getDurabilityBarValue(stack); + return Math.round(ItemEvents.GET_DURABILITY_VALUE.post((event, current) -> event.onEvent(stack, current), value) * 13f); + } + return Math.round(stack.getItem().getDurabilityBarValue(stack) * 13f); + } + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;hsvToRgb(FFF)I")) + public int damageColour(float hue, float saturation, float brightness) { + org.sandboxpowered.api.item.ItemStack stack = stackThreadLocal.get(); + if (ItemEvents.GET_DURABILITY_COLOR.hasSubscribers()) { + return ItemEvents.GET_DURABILITY_COLOR.post((event, current) -> event.onEvent(stack, current), stack.getItem().getDurabilityBarColor(stack)); + } + return stack.getItem().getDurabilityBarColor(stack); + } + + @Redirect(method = "renderGuiItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getCount()I", ordinal = 0)) + public int renderStackSize(ItemStack itemStack) { + org.sandboxpowered.api.item.ItemStack sandboxStack = Wrappers.ITEMSTACK.toSandbox(itemStack); + stackThreadLocal.set(sandboxStack); + if (ItemEvents.DRAW_STACK_COUNT.hasSubscribers()) { + return ItemEvents.DRAW_STACK_COUNT.post((event, current) -> event.onEvent(sandboxStack, current), sandboxStack.getItem().shouldRenderStackCount(sandboxStack)) ? itemStack.getCount() : 1; + } + return itemStack.getCount(); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemStack.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemStack.java new file mode 100644 index 0000000..47bae75 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/MixinItemStack.java @@ -0,0 +1,239 @@ +package org.sandboxpowered.loader.mixin.injection.item; + +import net.minecraft.core.Registry; +import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.level.Level; +import org.apache.commons.lang3.NotImplementedException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.ecs.Entity; +import org.sandboxpowered.api.enchantment.Enchantment; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.util.nbt.CompoundTag; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.*; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +@Mixin(ItemStack.class) +@Implements(@Interface(iface = org.sandboxpowered.api.item.ItemStack.class, prefix = "stack$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinItemStack { + @Shadow + public abstract boolean isEmpty(); + + @Shadow + public abstract ItemStack copy(); + + @Shadow + public abstract int getCount(); + + @Shadow + public abstract void setCount(int p_190920_1_); + + @Shadow + public abstract int getMaxDamage(); + + @Shadow + public abstract int getDamageValue(); + + @Shadow + public abstract void setDamageValue(int p_196085_1_); + + @Shadow + public abstract boolean isDamaged(); + + @Shadow + public abstract boolean isDamageableItem(); + + @Shadow + public abstract int getMaxStackSize(); + + @Shadow + public abstract void shrink(int p_190918_1_); + + @Shadow + public abstract void grow(int p_190917_1_); + + @Shadow + public abstract net.minecraft.world.item.Item getItem(); + + @Shadow + public abstract ListTag getEnchantmentTags(); + + @Shadow + public abstract void hurtAndBreak(int i, T livingEntity, Consumer consumer); + + @NotNull + private org.sandboxpowered.api.item.ItemStack asSandbox(ItemStack stack) { + return Wrappers.ITEMSTACK.toSandbox(stack); + } + + @NotNull + private org.sandboxpowered.api.item.ItemStack asSandbox() { + return (org.sandboxpowered.api.item.ItemStack) this; + } + + @NotNull + private ItemStack asVanilla() { + return (ItemStack) (Object) this; + } + + @NotNull + private ItemStack asVanilla(org.sandboxpowered.api.item.ItemStack stack) { + return (ItemStack) (Object) stack; + } + + public boolean stack$isEmpty() { + return isEmpty(); + } + + @NotNull + public Item stack$getItem() { + return Wrappers.ITEM.toSandbox(getItem()); + } + + public int stack$getCount() { + return getCount(); + } + + @NotNull + public org.sandboxpowered.api.item.ItemStack stack$setCount(int amount) { + setCount(amount); + return asSandbox(); + } + + @NotNull + public org.sandboxpowered.api.item.ItemStack stack$copy() { + return asSandbox(copy()); + } + + @NotNull + public org.sandboxpowered.api.item.ItemStack stack$shrink(int amount) { + shrink(amount); + return asSandbox(); + } + + @NotNull + public org.sandboxpowered.api.item.ItemStack stack$grow(int amount) { + grow(amount); + return asSandbox(); + } + + public boolean stack$has(@NotNull Enchantment enchantment) { + return stack$getLevel(enchantment) > 0; + } + + public int stack$getLevel(@NotNull Enchantment enchantment) { + return EnchantmentHelper.getItemEnchantmentLevel(Wrappers.ENCHANTMENT.toVanilla(enchantment), asVanilla()); + } + + @NotNull + public Set stack$getEnchantments() { + if (stack$isEmpty()) + return Collections.emptySet(); + ListTag enchantments = getEnchantmentTags(); + return IntStream.range(0, enchantments.size()) + .mapToObj(enchantments::getCompound) + .map(tag -> tag.getString("id")) + .map(ResourceLocation::tryParse) + .filter(Objects::nonNull) + .map(Registry.ENCHANTMENT::get) + .filter(Objects::nonNull) + .map(Wrappers.ENCHANTMENT::toSandbox) + .collect(Collectors.toSet()); + } + + public boolean stack$hasTag() { + throw new NotImplementedException("TODO"); + } + + public @Nullable CompoundTag stack$getTag() { + throw new NotImplementedException("TODO"); + } + + public void stack$setTag(@NotNull CompoundTag tag) { + throw new NotImplementedException("TODO"); + } + + @NotNull + public CompoundTag stack$getOrCreateTag() { + throw new NotImplementedException("TODO"); + } + + public @Nullable CompoundTag stack$getChildTag(String key) { + throw new NotImplementedException("TODO"); + } + + @NotNull + public CompoundTag stack$getOrCreateChildTag(String key) { + throw new NotImplementedException("TODO"); + } + + @NotNull + public CompoundTag stack$asTag() { + throw new NotImplementedException("TODO"); + } + + public int stack$getMaxCount() { + return getMaxStackSize(); + } + + public boolean stack$isEqualTo(@NotNull org.sandboxpowered.api.item.ItemStack stack) { + return ItemStack.isSame(asVanilla(), asVanilla(stack)); + } + + public boolean stack$isEqualToIgnoreDurability(@NotNull org.sandboxpowered.api.item.ItemStack stack) { + return ItemStack.isSameIgnoreDurability(asVanilla(), asVanilla(stack)); + } + + public boolean stack$areTagsEqual(@NotNull org.sandboxpowered.api.item.ItemStack stack) { + return ItemStack.tagMatches(asVanilla(), asVanilla(stack)); + } + + public boolean stack$isDamaged() { + return isDamaged(); + } + + public boolean stack$isDamageable() { + return isDamageableItem(); + } + + public int stack$getMaxDamage() { + return getMaxDamage(); + } + + public int stack$getDamage() { + return getDamageValue(); + } + + public void stack$damage(int damage, @NotNull Entity entity) { + hurtAndBreak(damage, null, e -> { + }); + } + + public void stack$damage(int damage, @NotNull World world, int entity) { + Level level = Wrappers.WORLD.toVanilla(world); + net.minecraft.world.entity.Entity ent = level.getEntity(entity); + if (ent != null && ent instanceof LivingEntity) { + hurtAndBreak(damage, (LivingEntity) ent, e -> { + if(e.getMainHandItem() == asVanilla()) { + e.broadcastBreakEvent(InteractionHand.MAIN_HAND); + } else { + e.broadcastBreakEvent(InteractionHand.OFF_HAND); + } + }); + } + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttribute.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttribute.java new file mode 100644 index 0000000..b2b7314 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttribute.java @@ -0,0 +1,14 @@ +package org.sandboxpowered.loader.mixin.injection.item.attribute; + +import net.minecraft.world.entity.ai.attributes.Attribute; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(Attribute.class) +@Implements(@Interface(iface = org.sandboxpowered.api.item.attribute.Attribute.class, prefix = "attr$", remap = Interface.Remap.NONE)) +@Unique +public class MixinAttribute { + +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttributeModifier.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttributeModifier.java new file mode 100644 index 0000000..67e103e --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/attribute/MixinAttributeModifier.java @@ -0,0 +1,14 @@ +package org.sandboxpowered.loader.mixin.injection.item.attribute; + +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(AttributeModifier.class) +@Implements(@Interface(iface = org.sandboxpowered.api.item.attribute.Attribute.Modifier.class, prefix = "mods$", remap = Interface.Remap.NONE)) +@Unique +public class MixinAttributeModifier { + +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/tool/MixinTier.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/tool/MixinTier.java new file mode 100644 index 0000000..9c79748 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/item/tool/MixinTier.java @@ -0,0 +1,51 @@ +package org.sandboxpowered.loader.mixin.injection.item.tool; + +import net.minecraft.world.item.Tier; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.item.tool.ToolMaterial; +import org.sandboxpowered.api.recipe.Ingredient; +import org.spongepowered.asm.mixin.*; + +@Mixin(Tier.class) +@Implements(@Interface(iface = ToolMaterial.class, prefix = "material$", remap = Interface.Remap.NONE)) +@Unique +public interface MixinTier { + @Shadow + int getUses(); + + @Shadow + float getSpeed(); + + @Shadow + float getAttackDamageBonus(); + + @Shadow + int getLevel(); + + @Shadow + int getEnchantmentValue(); + + default int material$getDurability() { + return getUses(); + } + + default float material$getDigSpeed() { + return getSpeed(); + } + + default float material$getAttackDamage() { + return getAttackDamageBonus(); + } + + default int material$getMiningLevel() { + return getLevel(); + } + + default int material$getEnchantmentValue() { + return getEnchantmentValue(); + } + + default Ingredient material$getRepairIngredient() { + return null; + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinBlockPos.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinBlockPos.java new file mode 100644 index 0000000..6ca72b6 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinBlockPos.java @@ -0,0 +1,60 @@ +package org.sandboxpowered.loader.mixin.injection.math; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Vec3i; +import org.sandboxpowered.api.util.Direction; +import org.sandboxpowered.api.util.math.Position; +import org.spongepowered.asm.mixin.*; + +@Mixin(BlockPos.class) +@Implements(@Interface(iface = Position.class, prefix = "pos$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinBlockPos extends Vec3i { + public MixinBlockPos(int i, int j, int k) { + super(i, j, k); + } + + @Shadow + public abstract BlockPos immutable(); + + @Shadow + public abstract BlockPos offset(int i, int j, int k); + + public Position pos$add(int x, int y, int z) { + return (Position) offset(x, y, z); + } + + public Position pos$sub(int x, int y, int z) { + return pos$add(-x, -y, -z); + } + + public Position pos$offset(Direction direction, int amount) { + return null; + } + + public Position.Mutable pos$toMutable() { + return null; + } + + public Position pos$toImmutable() { + return (Position) immutable(); + } + + @Mixin(BlockPos.MutableBlockPos.class) + @Implements(@Interface(iface = Position.Mutable.class, prefix = "mutable$", remap = Interface.Remap.NONE)) + @Unique + public abstract static class MixinMutable extends MixinBlockPos { + @Shadow + public abstract BlockPos.MutableBlockPos set(int i, int j, int k); + + public MixinMutable(int i, int j, int k) { + super(i, j, k); + } + + public Position.Mutable mutable$set(int x, int y, int z) { + this.set(x, y, z); + return (Position.Mutable) this; + } + + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinVec3i.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinVec3i.java new file mode 100644 index 0000000..630929c --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/math/MixinVec3i.java @@ -0,0 +1,27 @@ +package org.sandboxpowered.loader.mixin.injection.math; + +import net.minecraft.core.Vec3i; +import org.spongepowered.asm.mixin.*; + +@Mixin(Vec3i.class) +@Implements(@Interface(iface = org.sandboxpowered.api.util.math.Vec3i.class, prefix = "vec$", remap = Interface.Remap.NONE)) +@Unique +public abstract class MixinVec3i { + @Shadow public abstract int getX(); + + @Shadow public abstract int getY(); + + @Shadow public abstract int getZ(); + + public int pos$getX() { + return getX(); + } + + public int pos$getY() { + return getY(); + } + + public int pos$getZ() { + return getZ(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/player/MixinPlayer.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/player/MixinPlayer.java new file mode 100644 index 0000000..f823811 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/player/MixinPlayer.java @@ -0,0 +1,16 @@ +package org.sandboxpowered.loader.mixin.injection.player; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(Player.class) +@Unique +public abstract class MixinPlayer extends LivingEntity { + public MixinPlayer(EntityType entityType, Level level) { + super(entityType, level); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinBlockGetter.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinBlockGetter.java new file mode 100644 index 0000000..42e5b74 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinBlockGetter.java @@ -0,0 +1,38 @@ +package org.sandboxpowered.loader.mixin.injection.world; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.state.FluidState; +import org.sandboxpowered.api.tags.TagManager; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.WorldReader; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.*; + +@Mixin(BlockGetter.class) +@Implements(@Interface(iface = WorldReader.class, prefix = "reader$", remap = Interface.Remap.NONE)) +@Unique +public interface MixinBlockGetter { + @Shadow net.minecraft.world.level.block.state.BlockState getBlockState(BlockPos blockPos); + + @Shadow @Nullable net.minecraft.world.level.block.entity.BlockEntity getBlockEntity(BlockPos blockPos); + + default BlockState reader$getBlockState(Position position) { + return Wrappers.BLOCKSTATE.toSandbox(getBlockState(Wrappers.POSITION.toVanilla(position))); + } + + default FluidState reader$getFluidState(Position position) { + return null; + } + + default long reader$getWorldTime() { + return 0; + } + + default TagManager reader$getTagManager() { + return null; + } + +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinLevel.java b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinLevel.java new file mode 100644 index 0000000..528b788 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/injection/world/MixinLevel.java @@ -0,0 +1,46 @@ +package org.sandboxpowered.loader.mixin.injection.world; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.item.ItemStack; +import org.sandboxpowered.api.state.BlockState; +import org.sandboxpowered.api.util.Side; +import org.sandboxpowered.api.util.math.Position; +import org.sandboxpowered.api.world.BlockFlag; +import org.sandboxpowered.api.world.World; +import org.sandboxpowered.api.world.WorldReader; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.*; + +@Mixin(Level.class) +@Implements({@Interface(iface = WorldReader.class, prefix = "reader$", remap = Interface.Remap.NONE), @Interface(iface = World.class, prefix = "world$", remap = Interface.Remap.NONE)}) +@Unique +public abstract class MixinLevel implements LevelAccessor { + @Shadow + @Nullable + public abstract MinecraftServer getServer(); + + @Shadow public abstract boolean setBlock(BlockPos blockPos, net.minecraft.world.level.block.state.BlockState blockState, int i); + + public Side world$getSide() { + return ((Object) this) instanceof ServerLevel ? Side.SERVER : Side.CLIENT; + } + + public void world$spawnItem(double x, double y, double z, ItemStack stack) { + ItemEntity entity = new ItemEntity(Level.class.cast(this), x, y, z, Wrappers.ITEMSTACK.toVanilla(stack)); + addFreshEntity(entity); + } + + public boolean world$setBlockState(Position position, BlockState state, BlockFlag... flags) { + return setBlock( + Wrappers.POSITION.toVanilla(position), + Wrappers.BLOCKSTATE.toVanilla(state), + 3 + ); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinDedicatedServer.java b/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinDedicatedServer.java new file mode 100644 index 0000000..4bce5a9 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinDedicatedServer.java @@ -0,0 +1,4 @@ +package org.sandboxpowered.loader.mixin.loading; + +public class MixinDedicatedServer { +} diff --git a/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinIntegratedServer.java b/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinIntegratedServer.java new file mode 100644 index 0000000..a1f6e31 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/mixin/loading/MixinIntegratedServer.java @@ -0,0 +1,50 @@ +package org.sandboxpowered.loader.mixin.loading; + +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.minecraft.MinecraftSessionService; +import com.mojang.datafixers.DataFixer; +import net.minecraft.client.server.IntegratedServer; +import net.minecraft.core.RegistryAccess; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerResources; +import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.players.GameProfileCache; +import net.minecraft.world.level.storage.LevelStorageSource; +import net.minecraft.world.level.storage.WorldData; +import org.sandboxpowered.loader.platform.Platform; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.io.IOException; +import java.net.Proxy; + +@Mixin(IntegratedServer.class) +public abstract class MixinIntegratedServer extends MinecraftServer { + public MixinIntegratedServer(Thread thread, RegistryAccess.RegistryHolder registryHolder, LevelStorageSource.LevelStorageAccess levelStorageAccess, WorldData worldData, PackRepository packRepository, Proxy proxy, DataFixer dataFixer, ServerResources serverResources, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory) { + super(thread, registryHolder, levelStorageAccess, worldData, packRepository, proxy, dataFixer, serverResources, minecraftSessionService, gameProfileRepository, gameProfileCache, chunkProgressListenerFactory); + } + + @Inject(method = "initServer", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/server/IntegratedServer;loadLevel()V", + shift = At.Shift.BEFORE), + cancellable = true + ) + public void setupServer(CallbackInfoReturnable info) throws IOException { + Platform.getPlatform().load(this, storageSource); + } + + @Inject(method = "stopServer", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/MinecraftServer;stopServer()V", + shift = At.Shift.BEFORE), + cancellable = true + ) + public void setupServer(CallbackInfo info) throws IOException { + Platform.getPlatform().unload(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackRespositorySource.java b/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackRespositorySource.java new file mode 100644 index 0000000..ce1c987 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackRespositorySource.java @@ -0,0 +1,43 @@ +package org.sandboxpowered.loader.packs; + +import net.minecraft.server.packs.FilePackResources; +import net.minecraft.server.packs.FolderPackResources; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.repository.Pack; +import net.minecraft.server.packs.repository.PackSource; +import net.minecraft.server.packs.repository.RepositorySource; +import org.sandboxpowered.internal.AddonSpec; +import org.sandboxpowered.loader.loading.SandboxLoader; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; + +import java.io.File; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class AddonPackRespositorySource implements RepositorySource { + @Override + public void loadPacks(Consumer consumer, Pack.PackConstructor packConstructor) { + SandboxPlatform platform = Platform.getPlatform(); + if (platform.isLoaded()) { + SandboxLoader loader = platform.getLoader(); + List packs = new ArrayList<>(); + loader.getAllAddons().forEach((addonSpec, addon) -> { + try { + packs.add(createAddonPack(addonSpec, new File(addonSpec.getPath().toURI()))); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + }); + Pack pack = Pack.create("Addon Resources", true, () -> new MergedSandboxPack("addon_resources", "Addon Resources", packs), packConstructor, Pack.Position.BOTTOM, PackSource.DEFAULT); + if (pack != null) + consumer.accept(pack); + } + } + + private PackResources createAddonPack(AddonSpec spec, File file) { + return new AddonPackWrapper(spec, file.isDirectory() ? new FolderPackResources(file) : new FilePackResources(file)); + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackWrapper.java b/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackWrapper.java new file mode 100644 index 0000000..a14a6e3 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/packs/AddonPackWrapper.java @@ -0,0 +1,109 @@ +package org.sandboxpowered.loader.packs; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import net.minecraft.SharedConstants; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.AbstractPackResources; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.ResourcePackFileNotFoundException; +import net.minecraft.server.packs.metadata.MetadataSectionSerializer; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.internal.AddonSpec; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Set; +import java.util.function.Predicate; + +public class AddonPackWrapper implements PackResources { + private static final Gson GSON = new Gson(); + private final AddonSpec spec; + private final PackResources resources; + + public AddonPackWrapper(AddonSpec spec, PackResources resources) { + this.spec = spec; + this.resources = resources; + } + + @Override + public InputStream getRootResource(String string) throws IOException { + try { + return resources.getRootResource(string); + } catch (ResourcePackFileNotFoundException e) { + if ("pack.mcmeta".equals(string)) { + JsonObject meta = new JsonObject(); + JsonObject pack = new JsonObject(); + pack.addProperty("pack_format", SharedConstants.getCurrentVersion().getPackVersion()); + pack.addProperty("description", spec.getDescription()); + meta.add("pack", pack); + return new ByteArrayInputStream(GSON.toJson(meta).getBytes(StandardCharsets.UTF_8)); + } + throw e; + } + } + + @Override + public InputStream getResource(PackType packType, ResourceLocation resourceLocation) throws IOException { + return resources.getResource(packType, resourceLocation); + } + + @Override + public Collection getResources(PackType packType, String string, String string2, int i, Predicate predicate) { + return resources.getResources(packType, string, string2, i, predicate); + } + + @Override + public boolean hasResource(PackType packType, ResourceLocation resourceLocation) { + return resources.hasResource(packType, resourceLocation); + } + + @Override + public Set getNamespaces(PackType packType) { + return resources.getNamespaces(packType); + } + + @Nullable + @Override + public T getMetadataSection(MetadataSectionSerializer metadataSectionSerializer) throws IOException { + InputStream inputStream = this.getRootResource("pack.mcmeta"); + Throwable error = null; + + T metadata; + try { + metadata = AbstractPackResources.getMetadataFromStream(metadataSectionSerializer, inputStream); + } catch (Throwable throwable) { + error = throwable; + throw throwable; + } finally { + if (inputStream != null) { + if (error != null) { + try { + inputStream.close(); + } catch (Throwable suppressed) { + error.addSuppressed(suppressed); + } + } else { + inputStream.close(); + } + } + + } + + return metadata; + } + + @Override + public String getName() { + return spec.getTitle(); + } + + @Override + public void close() { + resources.close(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/packs/MergedSandboxPack.java b/common/src/main/java/org/sandboxpowered/loader/packs/MergedSandboxPack.java new file mode 100644 index 0000000..e78c7ee --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/packs/MergedSandboxPack.java @@ -0,0 +1,158 @@ +package org.sandboxpowered.loader.packs; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import net.minecraft.SharedConstants; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.AbstractPackResources; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.ResourcePackFileNotFoundException; +import net.minecraft.server.packs.metadata.MetadataSectionSerializer; +import org.jetbrains.annotations.Nullable; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class MergedSandboxPack extends AbstractPackResources { + private final List delegates; + private final Map> namespacesAssets; + private final Map> namespacesData; + private final String name; + + public MergedSandboxPack(String id, String name, List packs) { + super(new File(id)); + this.delegates = ImmutableList.copyOf(packs); + this.name = name; + namespacesAssets = createNamespaceTypeMap(PackType.CLIENT_RESOURCES, delegates); + namespacesData = createNamespaceTypeMap(PackType.SERVER_DATA, delegates); + } + + private Map> createNamespaceTypeMap(PackType type, List packList) { + Map> map = new HashMap<>(); + + for (PackResources pack : packList) { + for (String namespace : pack.getNamespaces(type)) { + map.computeIfAbsent(namespace, (k) -> new ArrayList<>()).add(pack); + } + } + + map.replaceAll((k, list) -> ImmutableList.copyOf(list)); + return ImmutableMap.copyOf(map); + } + + @Override + protected InputStream getResource(String string) throws IOException { + throw new ResourcePackFileNotFoundException(this.file, string); + } + + @Override + public InputStream getRootResource(String string) throws IOException { + throw new ResourcePackFileNotFoundException(this.file, string); + } + + @Override + protected boolean hasResource(String string) { + return false; + } + + @Override + public boolean hasResource(PackType packType, ResourceLocation resourceLocation) { + for (PackResources pack : this.getPackSubset(packType, resourceLocation)) { + if (pack.hasResource(packType, resourceLocation)) + return true; + } + return false; + } + + private static final Gson GSON = new Gson(); + + public InputStream getPackMeta() { + JsonObject meta = new JsonObject(); + JsonObject pack = new JsonObject(); + pack.addProperty("pack_format", SharedConstants.getCurrentVersion().getPackVersion()); + pack.addProperty("description", String.format("Sandbox addon resources (%d)", delegates.size())); + meta.add("pack", pack); + return new ByteArrayInputStream(GSON.toJson(meta).getBytes(StandardCharsets.UTF_8)); + } + + @Nullable + @Override + public T getMetadataSection(MetadataSectionSerializer metadataSectionSerializer) throws IOException { + if (metadataSectionSerializer.getMetadataSectionName().equals("pack")) { + InputStream inputStream = getPackMeta(); + Throwable error = null; + try { + return AbstractPackResources.getMetadataFromStream(metadataSectionSerializer, inputStream); + } catch (Throwable throwable) { + error = throwable; + throw throwable; + } finally { + if (inputStream != null) { + if (error != null) { + try { + inputStream.close(); + } catch (Throwable suppressed) { + error.addSuppressed(suppressed); + } + } else { + inputStream.close(); + } + } + } + } + return null; + } + + @Override + public InputStream getResource(PackType packType, ResourceLocation resourceLocation) throws IOException { + for (PackResources pack : this.getPackSubset(packType, resourceLocation)) { + if (pack.hasResource(packType, resourceLocation)) + return pack.getResource(packType, resourceLocation); + } + throw new ResourcePackFileNotFoundException(this.file, getFullPath(packType, resourceLocation)); + } + + private static String getFullPath(PackType type, ResourceLocation location) { + return String.format("%s/%s/%s", type.getDirectory(), location.getNamespace(), location.getPath()); + } + + @Override + public Collection getResources(PackType type, String pathIn, String pathIn2, int maxDepth, Predicate filter) { + return this.delegates.stream() + .flatMap((pack) -> pack.getResources(type, pathIn, pathIn2, maxDepth, filter).stream()) + .collect(Collectors.toList()); + } + + @Override + public Set getNamespaces(PackType type) { + return getNamespaceMap(type).keySet(); + } + + private List getPackSubset(PackType type, ResourceLocation location) { + List packsWithNamespace = getNamespaceMap(type).get(location.getNamespace()); + return packsWithNamespace == null ? Collections.emptyList() : packsWithNamespace; + } + + public Map> getNamespaceMap(PackType type) { + return type == PackType.CLIENT_RESOURCES ? this.namespacesAssets : this.namespacesData; + } + + @Override + public String getName() { + return name; + } + + @Override + public void close() { + delegates.forEach(PackResources::close); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/platform/Platform.java b/common/src/main/java/org/sandboxpowered/loader/platform/Platform.java new file mode 100644 index 0000000..ca0d224 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/platform/Platform.java @@ -0,0 +1,15 @@ +package org.sandboxpowered.loader.platform; + +import com.google.inject.Inject; + +public class Platform { + @Inject + private static SandboxPlatform platform; + + public static SandboxPlatform getPlatform() { + if (platform == null) { + throw new IllegalStateException("Sandbox has not been initialized!"); + } + return platform; + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/platform/SandboxPlatform.java b/common/src/main/java/org/sandboxpowered/loader/platform/SandboxPlatform.java new file mode 100644 index 0000000..563df28 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/platform/SandboxPlatform.java @@ -0,0 +1,22 @@ +package org.sandboxpowered.loader.platform; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.storage.LevelStorageSource; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.loading.SandboxLoader; + +import java.io.IOException; + +public interface SandboxPlatform { + Identity getIdentity(); + + void load(MinecraftServer server, LevelStorageSource.LevelStorageAccess storageSource) throws IOException; + + void unload() throws IOException; + + void init(); + + boolean isLoaded(); + + SandboxLoader getLoader(); +} diff --git a/common/src/main/java/org/sandboxpowered/loader/platform/package-info.java b/common/src/main/java/org/sandboxpowered/loader/platform/package-info.java new file mode 100644 index 0000000..0279c08 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/platform/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.platform; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/service/BaseInternalService.java b/common/src/main/java/org/sandboxpowered/loader/service/BaseInternalService.java new file mode 100644 index 0000000..de1c1e0 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/service/BaseInternalService.java @@ -0,0 +1,80 @@ +package org.sandboxpowered.loader.service; + +import net.minecraft.tags.BlockTags; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.block.Material; +import org.sandboxpowered.api.client.Client; +import org.sandboxpowered.api.capability.Capability; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.fluid.Fluid; +import org.sandboxpowered.api.fluid.FluidStack; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.server.Server; +import org.sandboxpowered.api.state.property.Property; +import org.sandboxpowered.api.tags.Tag; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.api.util.math.Vec2i; +import org.sandboxpowered.api.util.math.Vec3d; +import org.sandboxpowered.api.util.math.Vec3i; +import org.sandboxpowered.api.util.nbt.CompoundTag; +import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; +import org.sandboxpowered.api.util.text.Text; +import org.sandboxpowered.internal.InternalService; + +public abstract class BaseInternalService implements InternalService { + + @Override + public Text createLiteralText(String text) { + return null; + } + + @Override + public Text createTranslatedText(String translation) { + return null; + } + + @Override + public > Property getProperty(String property) { + return null; + } + + @Override + public Server serverInstance() { + return null; + } + + @Override + public Capability componentFunction(Class c) { + return null; + } + + @Override + public FluidStack fluidStackFunction(Fluid fluid, int amount) { + return null; + } + + @Override + public FluidStack fluidStackFromTagFunction(ReadableCompoundTag tag) { + return null; + } + + @Override + public Identity.Variant createVariantIdentity(Identity identity, String variant) { + return null; + } + + @Override + public Client clientInstance() { + return null; + } + + @Override + public > Registry registryFunction(Class c) { + return null; + } + + @Override + public Tag getBlockTag(String string) { + return (Tag) BlockTags.BEACON_BASE_BLOCKS; + } +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/service/package-info.java b/common/src/main/java/org/sandboxpowered/loader/service/package-info.java new file mode 100644 index 0000000..7e2a2d1 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/service/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.service; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/util/DualEnumeration.java b/common/src/main/java/org/sandboxpowered/loader/util/DualEnumeration.java new file mode 100644 index 0000000..9c6fbf0 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/util/DualEnumeration.java @@ -0,0 +1,36 @@ +package org.sandboxpowered.loader.util; + +import java.util.Enumeration; + +public class DualEnumeration implements Enumeration { + private Enumeration first, second, selected; + + public DualEnumeration(Enumeration first, Enumeration second) { + this.first = first; + this.second = second; + this.selected = first; + } + + @Override + public boolean hasMoreElements() { + return selected != null && (selected.hasMoreElements() || selected == first && second.hasMoreElements()); + } + + @Override + public T nextElement() { + if (selected == null) { + return null; + } + + if (!selected.hasMoreElements()) { + if (selected == first) { + selected = second; + } else { + selected = null; + return null; + } + } + + return selected.nextElement(); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/util/MojangUtil.java b/common/src/main/java/org/sandboxpowered/loader/util/MojangUtil.java new file mode 100644 index 0000000..8ec518a --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/util/MojangUtil.java @@ -0,0 +1,12 @@ +package org.sandboxpowered.loader.util; + +public class MojangUtil { + /** + * This will return b if it is equal to a, in cases where mojang require a specific instance of an object, such as UUID. + */ + public static T checkMojangity(T a, T b) { + if (a.equals(b)) + return b; + return a; + } +} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/NumberUtil.java b/common/src/main/java/org/sandboxpowered/loader/util/NumberUtil.java similarity index 81% rename from src/main/java/org/sandboxpowered/sandbox/fabric/util/NumberUtil.java rename to common/src/main/java/org/sandboxpowered/loader/util/NumberUtil.java index 07fec0f..6822a8c 100644 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/NumberUtil.java +++ b/common/src/main/java/org/sandboxpowered/loader/util/NumberUtil.java @@ -1,4 +1,4 @@ -package org.sandboxpowered.sandbox.fabric.util; +package org.sandboxpowered.loader.util; import java.util.TreeMap; @@ -24,11 +24,11 @@ public class NumberUtil { private NumberUtil() { } - public static String toRoman(int number) { + public static String toRomanNumeral(int number) { int l = map.floorKey(number); if (number == l) { return map.get(number); } - return map.get(l) + toRoman(number - l); + return map.get(l) + toRomanNumeral(number - l); } } diff --git a/common/src/main/java/org/sandboxpowered/loader/util/SandboxImpl.java b/common/src/main/java/org/sandboxpowered/loader/util/SandboxImpl.java new file mode 100644 index 0000000..59b5add --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/util/SandboxImpl.java @@ -0,0 +1,8 @@ +package org.sandboxpowered.loader.util; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class SandboxImpl { + public static final Logger LOGGER = LogManager.getLogger("Sandbox"); +} diff --git a/common/src/main/java/org/sandboxpowered/loader/util/SandboxMode.java b/common/src/main/java/org/sandboxpowered/loader/util/SandboxMode.java new file mode 100644 index 0000000..06c34bf --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/util/SandboxMode.java @@ -0,0 +1,7 @@ +package org.sandboxpowered.loader.util; + +public enum SandboxMode { + DYNAMIC, + INTERACTIVE, + STATIC; +} diff --git a/common/src/main/java/org/sandboxpowered/loader/util/package-info.java b/common/src/main/java/org/sandboxpowered/loader/util/package-info.java new file mode 100644 index 0000000..76a167f --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/util/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.util; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/IVanillaBlock.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/IVanillaBlock.java new file mode 100644 index 0000000..18ff66f --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/IVanillaBlock.java @@ -0,0 +1,7 @@ +package org.sandboxpowered.loader.wrapper; + +import org.sandboxpowered.api.item.tool.ToolType; + +public interface IVanillaBlock { + void sandbox_setHarvestParams(ToolType type, int harvestLevel); +} diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/IWrappedItem.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/IWrappedItem.java new file mode 100644 index 0000000..1e00c02 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/IWrappedItem.java @@ -0,0 +1,9 @@ +package org.sandboxpowered.loader.wrapper; + +import org.sandboxpowered.api.item.Item; + +public interface IWrappedItem { + Item getAsSandbox(); + + net.minecraft.world.item.Item getAsVanilla(); +} diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlock.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlock.java new file mode 100644 index 0000000..baad8cb --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlock.java @@ -0,0 +1,73 @@ +package org.sandboxpowered.loader.wrapper; + +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.loader.Wrappers; + +import java.util.IdentityHashMap; + +public class WrappedBlock extends net.minecraft.world.level.block.Block { + private static final IdentityHashMap BLOCK_MAP = new IdentityHashMap<>(); + private final Block block; + + public static Properties from(Block.Settings settings) { + Properties properties = Properties.of(Wrappers.MATERIAL.toVanilla(settings.getMaterial())); + if (settings.doesRandomTick()) + properties.randomTicks(); + if (settings.getVelocity() > 0) + properties.speedFactor(settings.getVelocity()); + properties.jumpFactor(settings.getJumpVelocity()); + return properties; + } + + public WrappedBlock(Block block) { + super(from(block.getSettings())); + this.block = block; + } + + public static net.minecraft.world.level.block.Block convertSandboxBlock(Block block) { + if (block instanceof net.minecraft.world.level.block.Block) + return (net.minecraft.world.level.block.Block) block; + return BLOCK_MAP.computeIfAbsent(block, toWrap -> { + if (toWrap.getSettings().hasBlockEntity()) { + return new WithBE(toWrap); + } + return new WrappedBlock(toWrap); + }); + } + + public static Block convertVanillaBlock(net.minecraft.world.level.block.Block block) { + if (block instanceof WrappedBlock) + return ((WrappedBlock) block).block; + return (Block) block; + } + + @Override + public boolean isRandomlyTicking(BlockState blockState) { + return super.isRandomlyTicking(blockState); + } + + public Block getBlock() { + return block; + } + + public static class WithBE extends WrappedBlock implements EntityBlock { + public WithBE(Block block) { + super(block); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockGetter blockGetter) { +// return Wrappers.BLOCK_ENTITY.toVanilla(getBlock().createBlockEntity( +// Wrappers.WORLD_READER.toSandbox(blockGetter) +// )); + return null; + } + } + +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlockEntity.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlockEntity.java new file mode 100644 index 0000000..accf051 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedBlockEntity.java @@ -0,0 +1,16 @@ +package org.sandboxpowered.loader.wrapper; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.sandboxpowered.api.ecs.component.Component; + +import java.util.List; + +public class WrappedBlockEntity extends BlockEntity { + + private List components; + + public WrappedBlockEntity(BlockEntityType blockEntityType) { + super(blockEntityType); + } +} diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedItem.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedItem.java new file mode 100644 index 0000000..d6d0985 --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/WrappedItem.java @@ -0,0 +1,156 @@ +package org.sandboxpowered.loader.wrapper; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.item.BlockItem; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.util.text.Text; +import org.sandboxpowered.loader.Wrappers; + +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; + +public class WrappedItem extends net.minecraft.world.item.Item implements IWrappedItem { + private static final IdentityHashMap ITEM_MAP = new IdentityHashMap<>(); + private final Item item; + + public static Properties convert(Item.Settings settings) { + Properties properties = new Properties(); + properties.stacksTo(settings.getStackSize()); + properties.durability(settings.getDurability()); + if (settings.getRecipeRemainder() != null) + properties.craftRemainder(Wrappers.ITEM.toVanilla(settings.getRecipeRemainder())); + return properties; + } + + public WrappedItem(Item item) { + super(convert(item.getSettings())); + this.item = item; + } + + @Override + public Item getAsSandbox() { + return this.item; + } + + @Override + public net.minecraft.world.item.Item getAsVanilla() { + return this; + } + + public static net.minecraft.world.item.Item convertSandboxItem(Item item) { + if (item instanceof net.minecraft.world.item.Item) + return (net.minecraft.world.item.Item) item; + if (item instanceof BlockItem) + return ITEM_MAP.computeIfAbsent(item, i -> new WrappedItemBlock((BlockItem) i)).getAsVanilla(); + return ITEM_MAP.computeIfAbsent(item, WrappedItem::new).getAsVanilla(); + } + + public static Item convertVanillaItem(net.minecraft.world.item.Item item) { + if (item instanceof IWrappedItem) + return ((IWrappedItem) item).getAsSandbox(); + return (Item) item; + } + + @Override + public void appendHoverText(ItemStack itemStack, @Nullable Level level, List list, TooltipFlag tooltipFlag) { + item.appendTooltipText( + Wrappers.ITEMSTACK.toSandbox(itemStack), + Wrappers.WORLD.toSandbox(level), + (List) Wrappers.TEXT.toSandboxList(list), + tooltipFlag.isAdvanced() + ); + } + + @Override + public boolean isFoil(ItemStack itemStack) { + return item.showEnchantmentGlint(Wrappers.ITEMSTACK.toSandbox(itemStack)); + } + + @Override + public float getDestroySpeed(ItemStack itemStack, BlockState blockState) { + return item.getMiningSpeed( + Wrappers.ITEMSTACK.toSandbox(itemStack), Wrappers.BLOCKSTATE.toSandbox(blockState) + ); + } + + @Override + public boolean isCorrectToolForDrops(BlockState blockState) { + return item.isCorrectToolForDrops( + Wrappers.BLOCKSTATE.toSandbox(blockState) + ); + } + + @Override + public boolean mineBlock(ItemStack itemStack, Level level, BlockState blockState, BlockPos blockPos, LivingEntity livingEntity) { + return item.onMine( + Wrappers.ITEMSTACK.toSandbox(itemStack), + Wrappers.WORLD.toSandbox(level), + Wrappers.POSITION.toSandbox(blockPos), + Wrappers.BLOCKSTATE.toSandbox(blockState), + livingEntity.getId() + ); + } + + @Override + public int getEnchantmentValue() { + return item.getEnchantmentValue(); + } + + private Map> attributeModifiers; + + @Override + public Multimap getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { + if (attributeModifiers != null && attributeModifiers.containsKey(equipmentSlot)) + return attributeModifiers.get(equipmentSlot); + Multimap sbxMap = item.getAttributeModifiers( + Wrappers.EQUIPMENT_SLOT.toSandbox(equipmentSlot) + ); + if(sbxMap.isEmpty()) + return super.getDefaultAttributeModifiers(equipmentSlot); + ImmutableMultimap.Builder vanillaBuilder = ImmutableMultimap.builder(); + if (attributeModifiers == null) + attributeModifiers = new HashMap<>(); + sbxMap.forEach((attribute, modifier) -> vanillaBuilder.put( + Wrappers.ATTRIBUTE.toVanilla(attribute), + Wrappers.ATTRIBUTE_MODIFIER.toVanilla(modifier) + )); + Multimap vanillaMap = vanillaBuilder.build(); + attributeModifiers.put(equipmentSlot, vanillaMap); + return vanillaMap; + } + + public static class WrappedItemBlock extends net.minecraft.world.item.BlockItem implements IWrappedItem { + private final BlockItem item; + + public WrappedItemBlock(BlockItem item) { + super(Wrappers.BLOCK.toVanilla(item.asBlock()), new Properties()); + this.item = item; + } + + @Override + public Item getAsSandbox() { + return item; + } + + @Override + public net.minecraft.world.item.Item getAsVanilla() { + return this; + } + } + +} \ No newline at end of file diff --git a/common/src/main/java/org/sandboxpowered/loader/wrapper/package-info.java b/common/src/main/java/org/sandboxpowered/loader/wrapper/package-info.java new file mode 100644 index 0000000..f9c9f2a --- /dev/null +++ b/common/src/main/java/org/sandboxpowered/loader/wrapper/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.wrapper; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/common/src/main/resources/assets/sandbox/icon.png b/common/src/main/resources/assets/sandbox/icon.png new file mode 100644 index 0000000..8cf4b56 Binary files /dev/null and b/common/src/main/resources/assets/sandbox/icon.png differ diff --git a/common/src/main/resources/assets/sandbox/pack.png b/common/src/main/resources/assets/sandbox/pack.png new file mode 100644 index 0000000..8e4e145 Binary files /dev/null and b/common/src/main/resources/assets/sandbox/pack.png differ diff --git a/common/src/main/resources/fabric.mod.json b/common/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..fd8e5b2 --- /dev/null +++ b/common/src/main/resources/fabric.mod.json @@ -0,0 +1,6 @@ +{ + "schemaVersion": 1, + "id": "sandbox-common", + "version": "0.0.1", + "accessWidener": "sandbox.accesswidener" +} \ No newline at end of file diff --git a/common/src/main/resources/sandbox-common.mixins.json b/common/src/main/resources/sandbox-common.mixins.json new file mode 100644 index 0000000..7a71baa --- /dev/null +++ b/common/src/main/resources/sandbox-common.mixins.json @@ -0,0 +1,38 @@ +{ + "required": true, + "package": "org.sandboxpowered.loader.mixin", + "compatibilityLevel": "JAVA_11", + "minVersion": "0.8", + "mixinPriority": 5480, + "mixins": [ + "ecs.be.MixinBlockEntity", + "event.network.MixinMultiPlayerGameMode", + "event.network.MixinServerPlayerGameMode", + "fixes.enchantment_acceptable_item.MixinEnchantmentHelper", + "fixes.recipe_caching.MixinAbstractFurnaceBlockEntity", + "fixes.spawner_rendering.MixinBee", + "fixes.spawner_rendering.MixinEnderMan", + "injection.MixinEnchantmentCategory", + "injection.MixinEnchantmentCategory$MixinDiggerCategory", + "injection.MixinResourceLocation", + "injection.block.MixinBlock", + "injection.block.MixinCropBlock", + "injection.block.MixinMaterial", + "injection.blockstate.MixinBlockState", + "injection.experimental.MixinClientPackSource", + "injection.experimental.MixinServerPacksSource", + "injection.item.MixinItem", + "injection.item.MixinItemRenderer", + "injection.item.MixinItemStack", + "injection.item.attribute.MixinAttribute", + "injection.item.attribute.MixinAttributeModifier", + "injection.item.tool.MixinTier", + "injection.math.MixinBlockPos", + "injection.math.MixinBlockPos$MixinMutable", + "injection.math.MixinVec3i", + "injection.player.MixinPlayer", + "injection.world.MixinBlockGetter", + "injection.world.MixinLevel", + "loading.MixinIntegratedServer" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/sandbox.accesswidener b/common/src/main/resources/sandbox.accesswidener new file mode 100644 index 0000000..ddd1b6a --- /dev/null +++ b/common/src/main/resources/sandbox.accesswidener @@ -0,0 +1,4 @@ +accessWidener v1 named + +accessible field net/minecraft/world/item/Item BASE_ATTACK_DAMAGE_UUID Ljava/util/UUID; +accessible field net/minecraft/world/item/Item BASE_ATTACK_SPEED_UUID Ljava/util/UUID; \ No newline at end of file diff --git a/common/src/main/resources/test.md b/common/src/main/resources/test.md new file mode 100644 index 0000000..213dcc1 --- /dev/null +++ b/common/src/main/resources/test.md @@ -0,0 +1,88 @@ + +``` +package sandbox.example + +capability Example { + uint current_health // a property + uint max_health // another property +} +``` +## Types +### Primitive Types + +| Syntax | Type | Notes | +|-------------------|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `bool` | Boolean | True or false. | +| `uint`, `ulong` | Unsigned integer | Variable-length encoding; smaller values use fewer bits. | +| `int`, `long` | Signed integer | Variable-length encoding; smaller values use fewer bits. Negative values are represented in the usual two's-complement manner, and so use the maximum number of bits. | +| `sint`, `slong` | Zig-zag signed integer | Variable-length zig-zag encoding; smaller absolute values use fewer bits. More space-efficient than int32 or int64 when values are likely to be negative. | +| `float`, `double` | Floating Point | | +| `string` | String of characters | Strings should always be either ASCII or UTF-8. | +| `bytes` | Array of bytes | | +| `TagCompound` | Compound NBT Tag | | +| `Entity` | A capability set | A data structure that represents an arbitrary collection of components. | + +### Enumerations +You can define enumerations and use them like built-in types. Like types, enums can be defined within the scope of an outer type. + +Example: +``` +package sandbox.example + +enum Colour { + BLACK + RED + GREEN + BROWN + BLUE + PURPLE + CYAN + LIGHT_GRAY + GRAY + PINK + LIME + YELLOW + LIGHT_BLUE + MAGENTA + ORANGE + WHITE +} + +type Example { + Colour colour +} +``` + +### Collections + +The collection types available are: +- Optional: `T?` represents either no value (empty) or a single `T` value. +- Array/List: `T[]` represents zero or more `T` values. +- Map: `[K,V]` represents a map from keys of type `K` to values of type `V`. + +Example: +``` +package sandbox.example + +type Example { + uint? an_integer + uint[] integer_list + [uint,bool] integer_boolean_map +} +``` +You can create nested collections (like lists of lists, maps of lists, and so on), however you cannot create a list or map of optional values + +Example: +``` +package sandbox.example + +type Works { + uint[][] list_of_list + [uint, uint[]] map_of_list +} + +type Errors { + uint?[] list_of_optional + [uint, uint?] map_of_optional +} +``` \ No newline at end of file diff --git a/common/src/main/resources/test.schema b/common/src/main/resources/test.schema new file mode 100644 index 0000000..aed160d --- /dev/null +++ b/common/src/main/resources/test.schema @@ -0,0 +1,18 @@ +package org.sandboxpowered.ecs.capability; + +bool | Boolean | true or false + + +capability BlockEntityPosition { + id = 'be-position'; + sint x; + sint y; + sint z; +} + +capability EntityPosition { + id = 'entity-position'; + float x; + float y; + float z; +} \ No newline at end of file diff --git a/contracts/net/minecraft/client/annotations.xml b/contracts/net/minecraft/client/annotations.xml new file mode 100644 index 0000000..63322ed --- /dev/null +++ b/contracts/net/minecraft/client/annotations.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..c327fad --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,38 @@ +plugins { + id "com.github.johnrengelman.shadow" version "5.0.0" +} + +architectury { + platformSetupLoomIde() +} + +configurations { + shadow +} + +dependencies { + minecraft("com.mojang:minecraft:${rootProject.architect.minecraft}") + mappings(minecraft.officialMojangMappings()) + modCompile("net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}") + + compile(project(":common")) { + transitive = false + } + shadow(project(":common")) { + transitive = false + } + modRuntime ("com.github.SuperCoder7979:databreaker:715b589") { + exclude module: "fabric-loader" + } + runtime(project(":TestAddon")) +} + +shadowJar { + configurations = [project.configurations.shadow] + classifier "shadow" +} + +remapJar { + dependsOn(shadowJar) + input.set(shadowJar.archivePath) +} \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/SandboxFabric.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/SandboxFabric.java new file mode 100644 index 0000000..7daa3f3 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/SandboxFabric.java @@ -0,0 +1,33 @@ +package org.sandboxpowered.loader.fabric; + +import net.minecraft.core.Registry; +import net.minecraft.world.level.block.SlabBlock; +import net.minecraft.world.level.block.state.properties.StairsShape; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.CacheableRegistry; +import org.sandboxpowered.loader.SandboxCore; +import org.sandboxpowered.loader.Wrappers; + +public class SandboxFabric extends SandboxCore { + private final Identity ID = Identity.of("sandbox", "fabric"); + + @Override + public Identity getIdentity() { + return ID; + } + + @Override + protected void initCachedRegistries() { + setRegistryWrapper(Registry.BLOCK, Wrappers.BLOCK); + setRegistryWrapper(Registry.ITEM, Wrappers.ITEM); + setRegistryWrapper(Registry.FLUID, Wrappers.FLUID); + setRegistryWrapper(Registry.ENCHANTMENT, Wrappers.ENCHANTMENT); + } + + private , Y> void setRegistryWrapper(Registry registry, Wrappers.Wrapper wrapper) { + ((CacheableRegistry) registry).setWrapper(wrapper); + } +} diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/inject/FabricImplementationModule.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/inject/FabricImplementationModule.java new file mode 100644 index 0000000..34bcb77 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/inject/FabricImplementationModule.java @@ -0,0 +1,14 @@ +package org.sandboxpowered.loader.fabric.inject; + +import org.sandboxpowered.loader.fabric.SandboxFabric; +import org.sandboxpowered.loader.inject.SandboxImplementationModule; +import org.sandboxpowered.loader.platform.SandboxPlatform; + +public class FabricImplementationModule extends SandboxImplementationModule { + @Override + protected void configure() { + super.configure(); + + bind(SandboxPlatform.class).to(SandboxFabric.class); + } +} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinClientBrandRetriever.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinClientBrandRetriever.java similarity index 85% rename from src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinClientBrandRetriever.java rename to fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinClientBrandRetriever.java index 8ce46b9..633086d 100644 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinClientBrandRetriever.java +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinClientBrandRetriever.java @@ -1,4 +1,4 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; +package org.sandboxpowered.loader.fabric.mixin.brand; import net.minecraft.client.ClientBrandRetriever; import org.spongepowered.asm.mixin.Mixin; @@ -6,7 +6,6 @@ @Mixin(ClientBrandRetriever.class) public class MixinClientBrandRetriever { - /** * @reason Replace client branding * @author Coded diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinMinecraftClient.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinMinecraftClient.java new file mode 100644 index 0000000..3e9f9cf --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/brand/MixinMinecraftClient.java @@ -0,0 +1,27 @@ +package org.sandboxpowered.loader.fabric.mixin.brand; + +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(Minecraft.class) +public class MixinMinecraftClient { + + /** + * @reason Sandbox Client Branding + * @author Coded + */ + @Overwrite + public String getVersionType() { + return "Sandbox"; + } + + /** + * @reason Is definitely modded + * @author Coded + */ + @Overwrite + public boolean isProbablyModded() { + return true; + } +} \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinCreativeModeTab.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinCreativeModeTab.java new file mode 100644 index 0000000..d23d94c --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinCreativeModeTab.java @@ -0,0 +1,45 @@ +package org.sandboxpowered.loader.fabric.mixin.feature; + +import net.minecraft.client.Minecraft; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import org.sandboxpowered.api.events.ItemEvents; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(CreativeModeTab.class) +public class MixinCreativeModeTab { + @Shadow + @Final + private int id; + + @Inject(method = "fillItemList", at = @At("RETURN")) + public void appendStacks(NonNullList stacks, CallbackInfo info) { + boolean opOnly = Minecraft.getInstance().player.hasPermissions(2); + if (this.id == CreativeModeTab.TAB_BUILDING_BLOCKS.getId()) { + stacks.add(new ItemStack(Items.BARRIER)); + } + if (this.id == CreativeModeTab.TAB_DECORATIONS.getId()) { + stacks.add(new ItemStack(Items.DRAGON_EGG)); + } + if (opOnly) { + if (this.id == CreativeModeTab.TAB_TRANSPORTATION.getId()) { + stacks.add(new ItemStack(Items.COMMAND_BLOCK_MINECART)); + } + if (this.id == CreativeModeTab.TAB_REDSTONE.getId()) { + stacks.add(new ItemStack(Items.COMMAND_BLOCK)); + } + if (this.id == CreativeModeTab.TAB_MISC.getId()) { + stacks.add(new ItemStack(Items.STRUCTURE_BLOCK)); + stacks.add(new ItemStack(Items.STRUCTURE_VOID)); + stacks.add(new ItemStack(Items.DEBUG_STICK)); + } + } + } +} \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinEnchantment.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinEnchantment.java new file mode 100644 index 0000000..9f97ff0 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/feature/MixinEnchantment.java @@ -0,0 +1,17 @@ +package org.sandboxpowered.loader.fabric.mixin.feature; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.enchantment.Enchantment; +import org.sandboxpowered.loader.util.NumberUtil; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(Enchantment.class) +public class MixinEnchantment { + @Redirect(method = "getFullname", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/MutableComponent;append(Lnet/minecraft/network/chat/Component;)Lnet/minecraft/network/chat/MutableComponent;")) + private MutableComponent text(MutableComponent text, Component value, int i) { + return text.append(NumberUtil.toRomanNumeral(i)); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/loading/MixinBootstrap.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/loading/MixinBootstrap.java new file mode 100644 index 0000000..21926ab --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/loading/MixinBootstrap.java @@ -0,0 +1,30 @@ +package org.sandboxpowered.loader.fabric.mixin.loading; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import net.minecraft.server.Bootstrap; +import org.sandboxpowered.loader.fabric.inject.FabricImplementationModule; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.sandboxpowered.loader.util.SandboxImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Bootstrap.class) +public class MixinBootstrap { + @Shadow + private static boolean isBootstrapped; + + @Inject(method = "bootStrap", at = @At(value = "HEAD")) + private static void vanillaSnapshot(CallbackInfo info) { + if (!isBootstrapped) { + Injector injector = Guice.createInjector(new FabricImplementationModule()); + SandboxPlatform platform = Platform.getPlatform(); + SandboxImpl.LOGGER.info("Loading Sandbox implementation '{}'", platform.getIdentity()); + platform.init(); + } + } +} \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/registry/MixinMappedRegistry.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/registry/MixinMappedRegistry.java new file mode 100644 index 0000000..0bc6139 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/mixin/registry/MixinMappedRegistry.java @@ -0,0 +1,70 @@ +package org.sandboxpowered.loader.fabric.mixin.registry; + +import com.mojang.serialization.Lifecycle; +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.WritableRegistry; +import net.minecraft.resources.ResourceKey; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.loader.CacheableRegistry; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.fabric.SandboxFabric; +import org.sandboxpowered.loader.fabric.registry.WrappedRegistry; +import org.sandboxpowered.loader.fabric.registry.WrappedRegistryIndicator; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(MappedRegistry.class) +public abstract class MixinMappedRegistry> extends WritableRegistry implements CacheableRegistry, WrappedRegistryIndicator { + @Shadow + private int nextId; + private int vanillaNext; + private boolean hasStored; + private WrappedRegistry wrappedRegistry; + + public MixinMappedRegistry(ResourceKey> resourceKey, Lifecycle lifecycle) { + super(resourceKey, lifecycle); + } + + public void setWrappedRegistry(WrappedRegistry wrappedRegistry) { + this.wrappedRegistry = wrappedRegistry; + } + + @Override + public WrappedRegistry sandbox_getWrappedRegistry() { + return wrappedRegistry; + } + + @Override + public org.sandboxpowered.api.registry.Registry getSandboxRegistry() { + return sandbox_getWrappedRegistry(); + } + + @Override + public void setWrapper(Wrappers.Wrapper wrapper) { + setWrappedRegistry(new WrappedRegistry<>( + Wrappers.IDENTITY.toSandbox(key().location()), + this, + wrapper + )); +// SandboxFabric.CORE.getLog().debug("Setting cached registry '{}' to Sandbox: '{}' Vanilla: '{}'", wrappedRegistry.getIdentity(), wrapper.getSandboxType(), wrapper.getVanillaType()); + } + + @Override + public void saveRegistryContent() { + if (!hasStored) { + vanillaNext = nextId; + + hasStored = true; + } + } + + @Override + public void resetRegistryContent() { + if (hasStored) { + nextId = vanillaNext; + + hasStored = false; + } + } +} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/WrappedRegistry.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistry.java similarity index 51% rename from src/main/java/org/sandboxpowered/sandbox/fabric/impl/WrappedRegistry.java rename to fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistry.java index d77014a..971172f 100644 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/WrappedRegistry.java +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistry.java @@ -1,91 +1,86 @@ -package org.sandboxpowered.sandbox.fabric.impl; +package org.sandboxpowered.loader.fabric.registry; import com.mojang.serialization.Lifecycle; -import net.minecraft.util.registry.MutableRegistry; +import net.minecraft.resources.ResourceKey; +import org.jetbrains.annotations.Nullable; import org.sandboxpowered.api.content.Content; import org.sandboxpowered.api.registry.Registry; import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; +import org.sandboxpowered.loader.CacheableRegistry; +import org.sandboxpowered.loader.Wrappers; import java.util.*; import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.Stream; -public class WrappedRegistry, B> implements Registry { +public class WrappedRegistry, V> implements Registry, CacheableRegistry.Wrapped { private final Identity identity; - private final Map> cacheMap = new TreeMap<>(Comparator.comparing(Identity::getPath).thenComparing(Identity::getNamespace)); - private final Function convertAB; - private final Function convertBA; - private final net.minecraft.util.registry.Registry vanilla; - private final Class type; + private final Map> cacheMap = new TreeMap<>(Comparator.comparing(Identity::getPath).thenComparing(Identity::getNamespace)); + private final net.minecraft.core.WritableRegistry vanilla; + private final Wrappers.Wrapper wrapper; + private int cacheIndex = 0; - public WrappedRegistry(Identity identity, net.minecraft.util.registry.Registry vanilla, Class type, Function convertAB, Function convertBA) { + public WrappedRegistry(Identity identity, net.minecraft.core.WritableRegistry vanilla, Wrappers.Wrapper wrapper) { this.identity = identity; - this.convertAB = convertAB; - this.convertBA = convertBA; + this.wrapper = wrapper; this.vanilla = vanilla; - this.type = type; } @Override - public Identity getIdentity() { - return identity; + public net.minecraft.core.Registry toVanilla() { + return vanilla; } @Override - public Identity getIdentity(A val) { - return (Identity) vanilla.getId(convertAB.apply(val)); + public Registry toSandbox() { + return this; } @Override - public Entry get(Identity identity) { - return cacheMap.computeIfAbsent(identity, id -> new RegistryEntry<>(id, this)); + public Identity getIdentity(S val) { + return Wrappers.IDENTITY.toSandbox(vanilla.getKey(wrapper.toVanilla(val))); } - public A getCurrent(Identity identity) { - return convertBA.apply(vanilla.get(WrappingUtil.convert(identity))); + @Override + public Entry get(Identity identity) { + return cacheMap.computeIfAbsent(identity, id -> new RegistryEntry<>(id, this)); } - @SuppressWarnings("unchecked") @Override - public Entry register(Identity identity, A val) { - B conversion = convertAB.apply(val); - ((MutableRegistry) vanilla).add(WrappingUtil.convertToRegistryKey(((SandboxInternal.RegistryKeyObtainer) vanilla).sandboxGetRegistryKey(), identity), conversion, Lifecycle.experimental()); - return get(identity); + public Entry register(S val) { + vanilla.register(ResourceKey.create(vanilla.key(), Wrappers.IDENTITY.toVanilla(val.getIdentity())), wrapper.toVanilla(val), Lifecycle.experimental()); + return get(val.getIdentity()); } @Override - public Collection values() { - return vanilla.stream().map(convertBA).collect(Collectors.toList()); + public Stream stream() { + return vanilla.stream().map(wrapper::toSandbox); } @Override - public Stream stream() { - return vanilla.stream().map(convertBA); + public Collection keys() { + return Wrappers.IDENTITY.toSandboxList(vanilla.keySet()); } @Override - public Collection keys() { - return vanilla.getIds().stream().map(id -> (Identity) id).collect(Collectors.toList()); + public Class getType() { + return wrapper.getSandboxType(); } @Override - public Class getType() { - return type; + public Identity getIdentity() { + return identity; } - public void clearCache() { - cacheMap.forEach((id, aEntry) -> aEntry.clearCache()); + public void resetCache() { + cacheIndex++; } public static class RegistryEntry> implements Entry { private final Identity identity; private final WrappedRegistry registry; - private boolean hasCached; + private int cacheIndex = -1; private T cache; public RegistryEntry(Identity identity, WrappedRegistry registry) { @@ -95,19 +90,13 @@ public RegistryEntry(Identity identity, WrappedRegistry registry) { @Override public boolean isPresent() { - if (!hasCached) { - cache = registry.getCurrent(identity); - hasCached = true; - } + resetCachedValueIfApplicable(); return cache != null; } @Override public T get() { - if (!hasCached) { - cache = registry.getCurrent(identity); - hasCached = true; - } + resetCachedValueIfApplicable(); if (cache == null) throw new NoSuchElementException("No such registered object " + identity); return cache; @@ -115,16 +104,15 @@ public T get() { @Override public Optional getAsOptional() { - if (!hasCached) { - cache = registry.getCurrent(identity); - hasCached = true; - } + resetCachedValueIfApplicable(); return Optional.ofNullable(cache); } - public void clearCache() { - cache = null; - hasCached = false; + private void resetCachedValueIfApplicable() { + if (registry.cacheIndex != cacheIndex) { + cache = registry.getCurrent(identity); + cacheIndex = registry.cacheIndex; + } } @Override @@ -137,6 +125,11 @@ public T orElse(T other) { return getAsOptional().orElse(other); } + @Override + public @Nullable T orNull() { + return getAsOptional().orElse(null); + } + @Override public T orElseGet(Supplier other) { return getAsOptional().orElseGet(other); @@ -157,4 +150,8 @@ public void ifPresentOrElse(Consumer tConsumer, Runnable notPresent) { } } } + + private S getCurrent(Identity identity) { + return wrapper.toSandbox(vanilla.get(Wrappers.IDENTITY.toVanilla(identity))); + } } \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistryIndicator.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistryIndicator.java new file mode 100644 index 0000000..4eb5417 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/WrappedRegistryIndicator.java @@ -0,0 +1,7 @@ +package org.sandboxpowered.loader.fabric.registry; + +import org.sandboxpowered.api.content.Content; + +public interface WrappedRegistryIndicator,V> { + WrappedRegistry sandbox_getWrappedRegistry(); +} diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/package-info.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/package-info.java new file mode 100644 index 0000000..e652484 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/registry/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package org.sandboxpowered.loader.fabric.registry; + +import org.sandboxpowered.api.util.annotation.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/fabric/src/main/java/org/sandboxpowered/loader/fabric/service/FabricInternalService.java b/fabric/src/main/java/org/sandboxpowered/loader/fabric/service/FabricInternalService.java new file mode 100644 index 0000000..63e19d1 --- /dev/null +++ b/fabric/src/main/java/org/sandboxpowered/loader/fabric/service/FabricInternalService.java @@ -0,0 +1,33 @@ +package org.sandboxpowered.loader.fabric.service; + +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.fabric.registry.WrappedRegistry; +import org.sandboxpowered.loader.service.BaseInternalService; + +public class FabricInternalService extends BaseInternalService { + + private static final WrappedRegistry ITEM = createRegistry(net.minecraft.core.Registry.ITEM, Wrappers.ITEM); + private static final WrappedRegistry BLOCK = createRegistry(net.minecraft.core.Registry.BLOCK, Wrappers.BLOCK); + + @Override + public > Registry registryFunction(Class c) { + if (c == Item.class) + return (Registry) ITEM; + if (c == Block.class) + return (Registry) BLOCK; + return null; + } + + private static , V> WrappedRegistry createRegistry(net.minecraft.core.WritableRegistry registry, Wrappers.Wrapper wrapper) { + return new WrappedRegistry<>( + Wrappers.IDENTITY.toSandbox(registry.key().location()), + registry, + wrapper + ); + } + +} diff --git a/fabric/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService b/fabric/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService new file mode 100644 index 0000000..75cc238 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService @@ -0,0 +1 @@ +org.sandboxpowered.loader.fabric.service.FabricInternalService \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..ab3eb32 --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,9 @@ +{ + "schemaVersion": 1, + "id": "sandbox", + "version": "0.0.1", + "mixins": [ + "sandbox-common.mixins.json", + "sandbox.mixins.json" + ] +} \ No newline at end of file diff --git a/fabric/src/main/resources/sandbox.mixins.json b/fabric/src/main/resources/sandbox.mixins.json new file mode 100644 index 0000000..11446c0 --- /dev/null +++ b/fabric/src/main/resources/sandbox.mixins.json @@ -0,0 +1,17 @@ +{ + "required": true, + "package": "org.sandboxpowered.loader.fabric.mixin", + "compatibilityLevel": "JAVA_11", + "minVersion": "0.8", + "mixinPriority": 5480, + "mixins": [ + "feature.MixinCreativeModeTab", + "feature.MixinEnchantment", + "loading.MixinBootstrap", + "registry.MixinMappedRegistry" + ], + "client": [ + "brand.MixinClientBrandRetriever", + "brand.MixinMinecraftClient" + ] +} diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..d87e54e --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,54 @@ +plugins { + id "com.github.johnrengelman.shadow" version "5.0.0" +} + +configurations { + shadow +} + +architectury { + platformSetupLoomIde() +} + +loom { + mixinConfigs = ["sandbox.mixins.json", "sandbox-common.mixins.json"] +} + +repositories { + jcenter() + maven { url "https://files.minecraftforge.net/maven" } +} + +configurations { + shadow +} + +dependencies { + minecraft("com.mojang:minecraft:${rootProject.architect.minecraft}") + mappings(minecraft.officialMojangMappings()) + forge("net.minecraftforge:forge:${rootProject.architect.minecraft}-${rootProject.forge_version}") + + compileOnly(project(path: ":common")) { + transitive = false + } + runtimeOnly(project(path: ":common", configuration: "transformForgeFakeMod")) { + transitive = false + } + shadow(project(path: ":common", configuration: "transformForge")) { + transitive = false + } + runtime(project(":TestAddon")) +} + +shadowJar { + exclude "fabric.mod.json" + + configurations = [project.configurations.shadow] + classifier null +} + +remapJar { + dependsOn(shadowJar) + input.set(shadowJar.archivePath) + archiveClassifier = "forge" +} \ No newline at end of file diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 0000000..01c185b --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.forge=true \ No newline at end of file diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/SBXForgeMod.java b/forge/src/main/java/org/sandboxpowered/loader/forge/SBXForgeMod.java new file mode 100644 index 0000000..717d921 --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/SBXForgeMod.java @@ -0,0 +1,7 @@ +package org.sandboxpowered.loader.forge; + +import net.minecraftforge.fml.common.Mod; + +@Mod("sandbox-forge") +public class SBXForgeMod { +} diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/SandboxForgeCore.java b/forge/src/main/java/org/sandboxpowered/loader/forge/SandboxForgeCore.java new file mode 100644 index 0000000..8699500 --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/SandboxForgeCore.java @@ -0,0 +1,31 @@ +package org.sandboxpowered.loader.forge; + +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.CacheableRegistry; +import org.sandboxpowered.loader.SandboxCore; +import org.sandboxpowered.loader.Wrappers; + +public class SandboxForgeCore extends SandboxCore { + @Override + protected void initCachedRegistries() { + setRegistryWrapper(ForgeRegistries.BLOCKS, Wrappers.BLOCK); + setRegistryWrapper(ForgeRegistries.ITEMS, Wrappers.ITEM); + setRegistryWrapper(ForgeRegistries.FLUIDS, Wrappers.FLUID); + setRegistryWrapper(ForgeRegistries.ENCHANTMENTS, Wrappers.ENCHANTMENT); + } + + private , Y extends IForgeRegistryEntry> void setRegistryWrapper(IForgeRegistry registry, Wrappers.Wrapper wrapper) { + ((CacheableRegistry) registry).setWrapper(wrapper); + } + + @Override + public Identity getIdentity() { + return Identity.of("sandbox", "forge"); + } +} \ No newline at end of file diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/inject/ForgeImplementationModule.java b/forge/src/main/java/org/sandboxpowered/loader/forge/inject/ForgeImplementationModule.java new file mode 100644 index 0000000..92cd5e2 --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/inject/ForgeImplementationModule.java @@ -0,0 +1,14 @@ +package org.sandboxpowered.loader.forge.inject; + +import org.sandboxpowered.loader.forge.SandboxForgeCore; +import org.sandboxpowered.loader.inject.SandboxImplementationModule; +import org.sandboxpowered.loader.platform.SandboxPlatform; + +public class ForgeImplementationModule extends SandboxImplementationModule { + @Override + protected void configure() { + super.configure(); + + bind(SandboxPlatform.class).to(SandboxForgeCore.class); + } +} diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/injection/MixinForgeRegistry.java b/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/injection/MixinForgeRegistry.java new file mode 100644 index 0000000..81032ee --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/injection/MixinForgeRegistry.java @@ -0,0 +1,43 @@ +package org.sandboxpowered.loader.forge.mixin.injection; + +import net.minecraftforge.registries.ForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.loader.CacheableRegistry; +import org.sandboxpowered.loader.Wrappers; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(ForgeRegistry.class) +public class MixinForgeRegistry, V extends IForgeRegistryEntry> implements CacheableRegistry { + private Wrappers.Wrapper sandbox_wrapper; + + /** + * @author Coded + */ + @Overwrite(remap = false) + public boolean isLocked() { + return false; + } + + @Override + public void setWrapper(Wrappers.Wrapper wrapper) { + sandbox_wrapper = wrapper; + } + + @Override + public Registry getSandboxRegistry() { + return null; + } + + @Override + public void saveRegistryContent() { + + } + + @Override + public void resetRegistryContent() { + + } +} diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/loading/MixinBootstrap.java b/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/loading/MixinBootstrap.java new file mode 100644 index 0000000..e8a1293 --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/mixin/loading/MixinBootstrap.java @@ -0,0 +1,35 @@ +package org.sandboxpowered.loader.forge.mixin.loading; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import net.minecraft.server.Bootstrap; +import org.sandboxpowered.loader.forge.inject.ForgeImplementationModule; +import org.sandboxpowered.loader.platform.Platform; +import org.sandboxpowered.loader.platform.SandboxPlatform; +import org.sandboxpowered.loader.util.SandboxImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Bootstrap.class) +public class MixinBootstrap { + @Shadow + private static boolean isBootstrapped; + + @Inject(method = "bootStrap", at = @At(value = "HEAD")) + private static void head(CallbackInfo info) { + if (!isBootstrapped) { + Injector injector = Guice.createInjector(new ForgeImplementationModule()); + SandboxPlatform platform = Platform.getPlatform(); + SandboxImpl.LOGGER.info("Loading Sandbox implementation '{}'", platform.getIdentity()); + } + } + + @Inject(method = "bootStrap", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/registries/GameData;vanillaSnapshot()V")) + private static void vanillaSnapshot(CallbackInfo info) { + SandboxPlatform platform = Platform.getPlatform(); + platform.init(); + } +} \ No newline at end of file diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/registry/WrappedRegistry.java b/forge/src/main/java/org/sandboxpowered/loader/forge/registry/WrappedRegistry.java new file mode 100644 index 0000000..d928e6a --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/registry/WrappedRegistry.java @@ -0,0 +1,150 @@ +package org.sandboxpowered.loader.forge.registry; + +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; +import org.jetbrains.annotations.Nullable; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.api.util.Identity; +import org.sandboxpowered.loader.Wrappers; + +import java.util.Collection; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public class WrappedRegistry, V extends IForgeRegistryEntry> implements Registry { + private final Identity identity; + // private final Map> cacheMap = new TreeMap<>(Comparator.comparing(Identity::getPath).thenComparing(Identity::getNamespace)); + private final IForgeRegistry vanilla; + private final Wrappers.Wrapper wrapper; + private int cacheIndex = 0; + + public WrappedRegistry(Identity identity, IForgeRegistry vanilla, Wrappers.Wrapper wrapper) { + this.identity = identity; + this.wrapper = wrapper; + this.vanilla = vanilla; + } + + @Override + public Identity getIdentity(S val) { + return Wrappers.IDENTITY.toSandbox(vanilla.getKey(wrapper.toVanilla(val))); + } + + @Override + public Entry get(Identity identity) { + //wrapper.toSandbox(vanilla.get(Wrappers.IDENTITY.toVanilla(identity))) + //TODO create entry system + return null; + } + + @Override + public Entry register(S val) { + vanilla.register(wrapper.toVanilla(val).setRegistryName(Wrappers.IDENTITY.toVanilla(val.getIdentity()))); + return get(val.getIdentity()); + } + + @Override + public Stream stream() { + return vanilla.getValues().stream().map(wrapper::toSandbox); + } + + @Override + public Collection keys() { + return Wrappers.IDENTITY.toSandboxList(vanilla.getKeys()); + } + + @Override + public Class getType() { + return wrapper.getSandboxType(); + } + + @Override + public Identity getIdentity() { + return identity; + } + + public void resetCache() { + cacheIndex++; + } + + public static class RegistryEntry> implements Entry { + private final Identity identity; + private final WrappedRegistry registry; + private int cacheIndex = -1; + private T cache; + + public RegistryEntry(Identity identity, WrappedRegistry registry) { + this.identity = identity; + this.registry = registry; + } + + @Override + public boolean isPresent() { + resetCachedValueIfApplicable(); + return cache != null; + } + + @Override + public T get() { + resetCachedValueIfApplicable(); + if (cache == null) + throw new NoSuchElementException("No such registered object " + identity); + return cache; + } + + @Override + public Optional getAsOptional() { + resetCachedValueIfApplicable(); + return Optional.ofNullable(cache); + } + + private void resetCachedValueIfApplicable() { + if (registry.cacheIndex != cacheIndex) { + cache = registry.getCurrent(identity); + cacheIndex = registry.cacheIndex; + } + } + + @Override + public boolean matches(T other) { + return getAsOptional().map(a -> a == other).orElse(false); + } + + @Override + public T orElse(T other) { + return getAsOptional().orElse(other); + } + + @Override + public @Nullable T orNull() { + return getAsOptional().orElse(null); + } + + @Override + public T orElseGet(Supplier other) { + return getAsOptional().orElseGet(other); + } + + @Override + public void ifPresent(Consumer tConsumer) { + getAsOptional().ifPresent(tConsumer); + } + + @Override + public void ifPresentOrElse(Consumer tConsumer, Runnable notPresent) { + Optional tOptional = getAsOptional(); + if (tOptional.isPresent()) { + tConsumer.accept(tOptional.get()); + } else { + notPresent.run(); + } + } + } + + private S getCurrent(Identity identity) { + return wrapper.toSandbox(vanilla.getValue(Wrappers.IDENTITY.toVanilla(identity))); + } +} \ No newline at end of file diff --git a/forge/src/main/java/org/sandboxpowered/loader/forge/service/ForgeInternalService.java b/forge/src/main/java/org/sandboxpowered/loader/forge/service/ForgeInternalService.java new file mode 100644 index 0000000..c0faf34 --- /dev/null +++ b/forge/src/main/java/org/sandboxpowered/loader/forge/service/ForgeInternalService.java @@ -0,0 +1,32 @@ +package org.sandboxpowered.loader.forge.service; + +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; +import org.sandboxpowered.api.block.Block; +import org.sandboxpowered.api.content.Content; +import org.sandboxpowered.api.item.Item; +import org.sandboxpowered.api.registry.Registry; +import org.sandboxpowered.loader.Wrappers; +import org.sandboxpowered.loader.forge.registry.WrappedRegistry; +import org.sandboxpowered.loader.service.BaseInternalService; + +public class ForgeInternalService extends BaseInternalService { + + private static final Registry ITEM = createRegistry(ForgeRegistries.ITEMS, Wrappers.ITEM); + private static final Registry BLOCK = createRegistry(ForgeRegistries.BLOCKS, Wrappers.BLOCK); + + @Override + public > Registry registryFunction(Class c) { + if (c == Item.class) + return (Registry) ITEM; + if (c == Block.class) + return (Registry) BLOCK; + return null; + } + + + private static , S extends Content> Registry createRegistry(IForgeRegistry registry, Wrappers.Wrapper wrapper) { + return new WrappedRegistry<>(Wrappers.IDENTITY.toSandbox(registry.getRegistryName()), registry, wrapper); + } +} diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..5dd3d55 --- /dev/null +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,4 @@ + +public net.minecraft.world.item.Item field_111210_e + +public net.minecraft.world.item.Item field_185050_h \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..76a8ce8 --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,24 @@ +modLoader = "javafml" +loaderVersion = "[32,)" +license = "GNU LGPLv3" + +[[mods]] +modId = "sandbox-forge" +version = "${file.jarVersion}" +displayName = "Sandbox Forge" +authors = "SandboxPowered" +license = "GNU LGPLv3" + +[[dependencies.sandbox-forge]] +modId = "forge" +mandatory = true +versionRange = "[35.0.3,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.sandbox-forge]] +modId = "minecraft" +mandatory = true +versionRange = "[1.16,)" +ordering = "NONE" +side = "BOTH" \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService b/forge/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService new file mode 100644 index 0000000..05af0c4 --- /dev/null +++ b/forge/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService @@ -0,0 +1 @@ +org.sandboxpowered.loader.forge.service.ForgeInternalService \ No newline at end of file diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..e144336 --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "Sandbox Forge", + "pack_format": 6 + } +} \ No newline at end of file diff --git a/forge/src/main/resources/sandbox.mixins.json b/forge/src/main/resources/sandbox.mixins.json new file mode 100644 index 0000000..c99bfcc --- /dev/null +++ b/forge/src/main/resources/sandbox.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "org.sandboxpowered.loader.forge.mixin", + "refmap": "sandbox.refmap.json", + "compatibilityLevel": "JAVA_11", + "minVersion": "0.8", + "mixinPriority": 5480, + "mixins": [ + "injection.MixinForgeRegistry", + "loading.MixinBootstrap" + ], + "client": [ + ] +} diff --git a/gradle.properties b/gradle.properties index 88edeb4..745eb66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,14 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.16.4-pre2 -yarn_mappings=1 -loader_version=0.9.3+build.207 +org.gradle.parallel=false sandbox_version=0.5 maven_group=org.sandboxpowered -archives_base_name=sandbox-fabric +archives_base_name=sandbox + +minecraft_version=1.16.4 +yarn_mappings=6 + +mod_version = 1.0.0 + +fabric_loader_version=0.10.6+build.214 + +forge_version=35.0.3 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ac33e99..442d913 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 9bf5d95..2ea9e14 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,16 +1,20 @@ pluginManagement { repositories { jcenter() - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } + maven { url "https://maven.fabricmc.net/" } + maven { url "https://dl.bintray.com/shedaniel/cloth" } + maven { url "https://files.minecraftforge.net/maven/" } + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } gradlePluginPortal() } } +include("common") +include("fabric") +include("forge") + include 'TestAddon' includeBuild 'SandboxAPI' -rootProject.name = "sandbox-fabric" \ No newline at end of file +rootProject.name = "Sandbox" \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/Sandbox.java b/src/main/java/org/sandboxpowered/sandbox/fabric/Sandbox.java deleted file mode 100644 index 1f4fde1..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/Sandbox.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Pair; -import org.sandboxpowered.api.util.Side; -import org.sandboxpowered.sandbox.fabric.internal.ISandbox; - -import java.util.List; - -public class Sandbox implements ISandbox { - public static final String ID = "sandbox"; - public static final Sandbox SANDBOX = new Sandbox(); - - @Environment(EnvType.CLIENT) - public static void openClient(String prefix, List> addons) { - // No loading currently - } - - public static void open(String prefix, List> addons) { - if (SANDBOX.getSide().isClient()) - openClient(prefix, addons); - } - - @Override - public Side getSide() { - return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ? Side.CLIENT : Side.SERVER; - } - - public void reload() { - if (getSide().isClient()) - reloadClient(); - } - - @Environment(EnvType.CLIENT) - public void reloadClient() { - MinecraftClient.getInstance().reloadResources(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxComponents.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxComponents.java deleted file mode 100644 index ca2f652..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxComponents.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import org.sandboxpowered.api.component.Component; -import org.sandboxpowered.api.component.FluidContainer; -import org.sandboxpowered.api.component.Inventory; -import org.sandboxpowered.sandbox.fabric.util.exception.UnknownComponentException; - -public class SandboxComponents { - public static final Component INVENTORY_COMPONENT = new Component<>(Inventory.class); - public static final Component FLUID_CONTAINER_COMPONENT = new Component<>(FluidContainer.class); - - private SandboxComponents() { - } - - @SuppressWarnings("unchecked") - public static Component getComponent(Class xClass) { - if (xClass == Inventory.class) - return (Component) INVENTORY_COMPONENT; - if (xClass == FluidContainer.class) - return (Component) FLUID_CONTAINER_COMPONENT; - throw new UnknownComponentException(xClass); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxConfig.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxConfig.java deleted file mode 100644 index e29d542..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxConfig.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.config.Config; -import org.sandboxpowered.sandbox.fabric.config.ConfigValue; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class SandboxConfig { - public static final ConfigValue enchantmentDecimal; - public static final ConfigValue velocityKey; - public static final ConfigValue forwarding; - public static final ConfigValue addonSyncURL; - public static final ConfigValue disableAutoCrashSending; - public static final ConfigValue worldBorder; - public static final ConfigValue cullParticles; - public static final Config config; - - static { - try { - Path data = Paths.get("data"); - if (Files.notExists(data)) - Files.createDirectories(data); - config = new Config(data.resolve("sandbox.toml")); - enchantmentDecimal = config.get("enchantment.decimal"); - enchantmentDecimal.add(false); - enchantmentDecimal.setComment(" Whether the Enchantment tooltip uses decimal or roman numerals"); - forwarding = config.get("server.forwarding.enable"); - forwarding.add(ServerForwarding.NONE); - forwarding.setComment(" Use player info forwarding, 'NONE', 'BUNGEE', 'VELOCITY'"); - velocityKey = config.get("server.forwarding.key"); - velocityKey.add("KEY_HERE"); - velocityKey.setComment(" Secret key to authenticate with velocity"); - addonSyncURL = config.get("server.sync.url"); - addonSyncURL.add("https://example.com"); - addonSyncURL.setComment(" URL Prefix for the client to download server addons"); - - worldBorder = config.get("client.world-border"); - worldBorder.add(WorldBorder.VANILLA); - worldBorder.setComment(" Changes the texture of the world border"); - - disableAutoCrashSending = config.get("crash.disable-auto-report"); - disableAutoCrashSending.add(false); - disableAutoCrashSending.setComment(" Disables Sandbox automatically reporting crashes to the developers"); - - cullParticles = config.get("client.particle-culling"); - cullParticles.add(true); - cullParticles.setComment(" Enables culling particles not visible to the player"); - config.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static void updateBorderType(WorldBorder border) { - worldBorder.set(border); - config.save(); - } - - public enum ServerForwarding { - NONE, - BUNGEE, - VELOCITY; - - public boolean isForwarding() { - return this != NONE; - } - } - - public enum WorldBorder { - VANILLA("options.sandbox.worldborder.vanilla"), - LINES("options.sandbox.worldborder.lines", new Identifier(Sandbox.ID, "textures/misc/lines.png")), - GRID("options.sandbox.worldborder.grid", new Identifier(Sandbox.ID, "textures/misc/grid.png")), - DOTS("options.sandbox.worldborder.dots", new Identifier(Sandbox.ID, "textures/misc/dot.png")); - - private static final WorldBorder[] VALUES = values(); - - private final String translation; - private final Identifier texture; - - WorldBorder(String translation, Identifier texture) { - this.translation = translation; - this.texture = texture; - } - - WorldBorder(String translation) { - this(translation, null); - } - - public String getTranslation() { - return translation; - } - - public Identifier getTexture() { - return texture; - } - - public WorldBorder next() { - int next = ordinal() + 1; - if (next == VALUES.length) - next = 0; - return VALUES[next]; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxFabric.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxFabric.java deleted file mode 100644 index 3bdc138..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxFabric.java +++ /dev/null @@ -1,225 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import com.github.zafarkhaja.semver.Parser; -import com.github.zafarkhaja.semver.expr.Expression; -import com.github.zafarkhaja.semver.expr.ExpressionParser; -import com.google.common.collect.ImmutableMap; -import net.fabricmc.loader.api.FabricLoader; -import org.sandboxpowered.api.SandboxAPI; -import org.sandboxpowered.api.addon.Addon; -import org.sandboxpowered.api.addon.AddonInfo; -import org.sandboxpowered.api.content.Content; -import org.sandboxpowered.api.registry.Registrar; -import org.sandboxpowered.api.registry.Registry; -import org.sandboxpowered.api.resources.ResourceManager; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.Log; -import org.sandboxpowered.api.util.Side; -import org.sandboxpowered.internal.Sandbox; -import org.sandboxpowered.sandbox.fabric.util.AddonLog; - -import java.util.*; - -public class SandboxFabric implements Sandbox { - private static final Parser PARSER = ExpressionParser.newInstance(); - private static final Identity PLATFORM = Identity.of("sandboxpowered", "fabric"); - private static boolean ranChecks; - private static boolean optifine; - private final Map loadedAddons = new LinkedHashMap<>(); - private final Map addonMap = new LinkedHashMap<>(); - private final Map addonAPIs = new LinkedHashMap<>(); - private final Map addonRegistrars = new LinkedHashMap<>(); - - public static boolean isOptifineLoaded() { - runChecks(); - return optifine; - } - - private static void runChecks() { - if (!ranChecks) { - try { - Class.forName("optifine/Installer.class"); - optifine = true; - } catch (ClassNotFoundException e) { - optifine = false; - } - ranChecks = true; - } - } - - public void loadAddon(AddonInfo info, Addon addon) { - loadedAddons.put(info.getId(), info); - addonMap.put(info, addon); - } - - private List getLoadOrder() { - Set visited = new HashSet<>(); - List loadOrder = new ArrayList<>(); - for (AddonInfo info : getAllAddons().keySet()) { - handleDependencies(visited, loadOrder, info); - } - return loadOrder; - } - - public void initAll() { - getLoadOrder().forEach(info -> { - if (!info.getPlatformSupport(getPlatform()).canRun()) { - throw new IllegalStateException(String.format("Addon %s cannot run on platform %s!", info.getId(), getPlatform().toString())); - } - Addon addon = getAllAddons().get(info); - SandboxAPI api = getAPIFor(info); - try { - addon.init(api); - } catch (Exception e) { - throw new RuntimeException(String.format("Initialization for addon %s failed: %s", info.getId(), e.getMessage()), e); - } - }); - } - - public void registerAll() { - getLoadOrder().forEach(info -> { - if (!info.getPlatformSupport(getPlatform()).canRun()) { - throw new IllegalStateException(String.format("Addon %s cannot run on platform %s!", info.getId(), getPlatform().toString())); - } - Addon addon = getAllAddons().get(info); - Registrar registrar = getRegistrarFor(info); - try { - addon.register(registrar); - } catch (Exception e) { - throw new RuntimeException(String.format("Registration for addon %s failed: %s", info.getId(), e.getMessage()), e); - } - }); - ResourceManager.register(); - } - - //TODO: does this properly prevent circular dependencies while satisfying everything? - private void handleDependencies(Set visited, List order, AddonInfo info) { - if (visited.contains(info)) return; - visited.add(info); - Map dependencies = info.getDependencies(); - for (String dep : dependencies.keySet()) { - Optional optionalDep = getAddon(dep); - if (!optionalDep.isPresent()) - throw new IllegalStateException(String.format("Addon %s depends on other addon %s that isn't loaded!", info.getId(), dep)); - AddonInfo dependency = optionalDep.get(); - String versionString = dependencies.get(dep); - Expression version = PARSER.parse(versionString); - if (!version.interpret(dependency.getVersion())) - throw new IllegalStateException(String.format("Addon %s depends on %s version %s but found version %s instead!", info.getId(), dep, versionString, dependency.getVersion().toString())); - handleDependencies(visited, order, info); - } - order.add(info); - } - - @Override - public Identity getPlatform() { - return PLATFORM; - } - - @Override - public Optional getAddon(String addonId) { - return Optional.ofNullable(loadedAddons.get(addonId)); - } - - @Override - public Map getAllAddons() { - return ImmutableMap.copyOf(addonMap); - } - - @Override - public SandboxAPI getAPIFor(AddonInfo info) { - return addonAPIs.computeIfAbsent(info, AddonSpecificAPI::new); - } - - @Override - public Registrar getRegistrarFor(AddonInfo info) { - return addonRegistrars.computeIfAbsent(info, AddonSpecificRegistrar::new); - } - - public void destroy() { - loadedAddons.clear(); - addonMap.clear(); - addonAPIs.clear(); - addonRegistrars.clear(); - } - - public void reloadResources() { - org.sandboxpowered.sandbox.fabric.Sandbox.SANDBOX.reload(); - } - - public static class AddonSpecificRegistrar implements Registrar { - private final AddonInfo info; - - public AddonSpecificRegistrar(AddonInfo info) { - this.info = info; - } - - @Override - public AddonInfo getSourceAddon() { - return info; - } - - @Override - public > Registry.Entry getEntry(Identity identity, Class tClass) { - return getEntry(identity, Registry.getRegistryFromType(tClass)); - } - - @Override - public > Registry.Entry getEntry(Identity identity, Registry registry) { - return registry.get(identity); - } - - @Override - public > Registry.Entry register(Identity identity, T content) { - return Registry.getRegistryFromType(content.getContentType()).register(identity, content); - } - - @Override - public Optional getRegistrarService(Class tClass) { - return Optional.empty(); //TODO: Implement registrar services - } - } - - public class AddonSpecificAPI implements SandboxAPI { - private final AddonInfo info; - private final Log log; - - public AddonSpecificAPI(AddonInfo info) { - this.info = info; - this.log = new AddonLog(info); - } - - @Override - public boolean isAddonLoaded(String addonId) { - return loadedAddons.containsKey(addonId); - } - - @Override - public boolean isExternalModLoaded(String loader, String modId) { - if ("internal".equals(loader)) - return "optifine".equals(modId) && isOptifineLoaded(); - boolean universal = "universal".equals(loader); - if (universal || "fabric".equals(loader)) { - if (modId == null || modId.isEmpty()) - return !universal; - return FabricLoader.getInstance().isModLoaded(modId); - } - return false; - } - - @Override - public AddonInfo getSourceAddon() { - return info; - } - - @Override - public Side getSide() { - return org.sandboxpowered.sandbox.fabric.Sandbox.SANDBOX.getSide(); - } - - @Override - public Log getLog() { - return log; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxHooks.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxHooks.java deleted file mode 100644 index f23d8a7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxHooks.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import net.minecraft.util.registry.Registry; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.security.AddonSecurityPolicy; - -import java.security.Policy; - -public class SandboxHooks { - private SandboxHooks() { - } - - public static void shutdown() { - Registry.REGISTRIES.stream().map(registry -> (SandboxInternal.Registry) registry).forEach(SandboxInternal.Registry::sandboxReset); - } - - public static void setupGlobal() { - Policy.setPolicy(new AddonSecurityPolicy()); - } - - public static void close() { - //Nothing to close - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxOptions.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxOptions.java deleted file mode 100644 index d2f34ac..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxOptions.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import net.minecraft.client.options.BooleanOption; -import net.minecraft.client.options.CyclingOption; -import net.minecraft.text.TranslatableText; - -public class SandboxOptions { - private SandboxOptions() { - } - - public static final CyclingOption WORLD_BORDER = new CyclingOption("options.sandbox.worldborder", - (gameOptions, integer) -> SandboxConfig.updateBorderType(SandboxConfig.worldBorder.getEnum(SandboxConfig.WorldBorder.class).next()), - (options, cyclingOption) -> cyclingOption.getGenericLabel(new TranslatableText(SandboxConfig.worldBorder.getEnum(SandboxConfig.WorldBorder.class).getTranslation())) - ); - - public static final BooleanOption CULL_PARTICLES = new BooleanOption("options.sandbox.cullparticles", - options -> SandboxConfig.cullParticles.getBoolean(), - (options, value) -> SandboxConfig.cullParticles.set(value) - ); -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxResources.java b/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxResources.java deleted file mode 100644 index 4e22281..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/SandboxResources.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.sandboxpowered.sandbox.fabric; - -import com.google.common.collect.Sets; -import net.minecraft.resource.AbstractFileResourcePack; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; -import org.sandboxpowered.sandbox.fabric.util.ArrayUtil; -import org.sandboxpowered.sandbox.fabric.util.Log; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Stream; - -public class SandboxResources extends AbstractFileResourcePack { - private final Path basePath; - private final String separator; - - public SandboxResources(Path basePath) { - super(null); - this.basePath = basePath.toAbsolutePath().normalize(); - this.separator = basePath.getFileSystem().getSeparator(); - } - - private Path getPath(String... filenames) { - String filename = ArrayUtil.join(filenames, "/"); - if (filename.equals("pack.png")) - filename = "assets/sandbox/icon.png"; - Path childPath = basePath.resolve(filename.replace("/", separator)).toAbsolutePath().normalize(); - - if (childPath.startsWith(basePath) && Files.exists(childPath)) { - return childPath; - } else { - return null; - } - } - - @Override - protected InputStream openFile(String var1) throws IOException { - Path path = getPath(var1); - if (path != null && Files.isRegularFile(path)) { - return Files.newInputStream(path); - } - - throw new FileNotFoundException(var1); - } - - @Override - protected boolean containsFile(String filename) { - Path path = getPath(filename); - return path != null && Files.isRegularFile(path); - } - - @Override - public Collection findResources(ResourceType type, String namespace, String path, int depth, Predicate predicate) { - List ids = new ArrayList<>(); - String nioPath = path.replace("/", separator); - Path namespacePath = getPath(type.getDirectory(), namespace); - if (namespacePath != null) { - Path searchPath = namespacePath.resolve(nioPath).toAbsolutePath().normalize(); - - if (Files.exists(searchPath)) { - try (Stream stream = Files.walk(searchPath, depth)) { - stream.filter(Files::isRegularFile) - .filter(p -> { - String filename = p.getFileName().toString(); - return !filename.endsWith(".mcmeta") && predicate.test(filename); - }) - .map(namespacePath::relativize) - .map(p -> p.toString().replace(separator, "/")) - .forEach(s -> { - try { - ids.add(new Identifier(namespace, s)); - } catch (InvalidIdentifierException e) { - Log.error("Encountered an error loading sandbox resources", e); - } - }); - } catch (IOException e) { - Log.error("findResources at " + path + " in namespace " + namespace + " failed!", e); - } - } - } - - return ids; - } - - @Override - public Set getNamespaces(ResourceType var1) { - return Sets.newHashSet("minecraft", Sandbox.ID); - } - - @Override - public void close() { - - } - - @Override - public String getName() { - return "Sandbox Resources"; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonFolderResourcePack.java b/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonFolderResourcePack.java deleted file mode 100644 index 6b33998..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonFolderResourcePack.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.client; - -import com.google.common.collect.Sets; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import net.minecraft.resource.AbstractFileResourcePack; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.sandboxpowered.internal.AddonSpec; -import org.sandboxpowered.sandbox.fabric.util.ArrayUtil; -import org.sandboxpowered.sandbox.fabric.util.Log; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Stream; - -public class AddonFolderResourcePack extends AbstractFileResourcePack { - - private static final Gson GSON = new GsonBuilder().create(); - private final Path basePath; - private final String separator; - private final AddonSpec spec; - - public AddonFolderResourcePack(Path basePath, AddonSpec spec) { - super(basePath.toFile()); - this.basePath = basePath.toAbsolutePath().normalize(); - this.separator = basePath.getFileSystem().getSeparator(); - this.spec = spec; - } - - private Path getPath(String... filenames) { - String filename = ArrayUtil.join(filenames, "/"); - Path childPath = basePath.resolve(filename.replace("/", separator)).toAbsolutePath().normalize(); - - if (childPath.startsWith(basePath) && Files.exists(childPath)) { - return childPath; - } else { - return null; - } - } - - @Override - protected InputStream openFile(String filename) throws IOException { - Path path = getPath(filename); - if (path != null && Files.isRegularFile(path)) { - return Files.newInputStream(path); - } else if ("pack.mcmeta".equals(filename)) { //file not found, substitute one by using the addon spec description - JsonObject meta = new JsonObject(); - JsonObject pack = new JsonObject(); - pack.addProperty("pack_format", 4); - pack.addProperty("description", spec.getDescription()); - meta.add("pack", pack); - return new ByteArrayInputStream(GSON.toJson(meta).getBytes(StandardCharsets.UTF_8)); - } - - throw new FileNotFoundException(String.format("'%s' in ResourcePack '%s'", basePath, filename)); //mirror MC's ResourceNotFoundException - } - - @Override - protected boolean containsFile(String filename) { - if ("pack.mcmeta".equals(filename)) - return true; //return early because we are going to substitute a dummy file if it doesn't exist - Path path = getPath(filename); - return path != null && Files.isRegularFile(path); - } - - @Override - public Collection findResources(ResourceType type, String namespace, String path, int depth, Predicate predicate) { - List ids = new ArrayList<>(); - String nioPath = path.replace("/", separator); - - Path namespacePath = getPath(type.getDirectory(), namespace); - if (namespacePath != null) { - Path searchPath = namespacePath.resolve(nioPath).toAbsolutePath().normalize(); - - if (Files.exists(searchPath)) { - try (Stream stream = Files.walk(searchPath, depth)) { - stream.filter(Files::isRegularFile) - .filter(p -> { - String filename = p.getFileName().toString(); - return !filename.endsWith(".mcmeta") && predicate.test(filename); - }) - .map(namespacePath::relativize) - .map(p -> p.toString().replace(separator, "/")) - .forEach(s -> { - try { - ids.add(new Identifier(namespace, s)); - } catch (InvalidIdentifierException e) { - Log.error("Encountered an error loading sandbox resources", e); - } - }); - } catch (IOException e) { - Log.error("findResources at " + path + " in namespace " + namespace + " failed!", e); - } - } - } - - return ids; - } - - @Override - public Set getNamespaces(ResourceType type) { - Set namespaces = Sets.newHashSet(); - File baseFile = new File(this.base, type.getDirectory()); - File[] files = baseFile.listFiles((FilenameFilter) DirectoryFileFilter.DIRECTORY); - if (files != null) { - for (File file : files) { - String path = relativize(baseFile, file); - if (path.equals(path.toLowerCase(Locale.ROOT))) { - namespaces.add(path.substring(0, path.length() - 1)); - } else { - this.warnNonLowerCaseNamespace(path); - } - } - } - - return namespaces; - } - - @Override - public void close() { - // No closing required - } - - @Override - public String getName() { - return spec.getTitle() + " Resources"; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourceCreator.java b/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourceCreator.java deleted file mode 100644 index af127cd..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourceCreator.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.client; - -import net.minecraft.resource.ResourcePackProfile; -import net.minecraft.resource.ResourcePackProvider; - -import java.util.function.Consumer; - -public class AddonResourceCreator implements ResourcePackProvider { - - @Override - public void register(Consumer consumer, ResourcePackProfile.Factory factory) { -// SandboxServer.INSTANCE.loader.getAddons().forEach(spec -> { TODO -// try { -// Path path = Paths.get(spec.getPath().toURI()); -// if (Files.isDirectory(path)) { -// consumer.accept(ResourcePackProfile.of( -// spec.getTitle(), -// true, -// () -> new AddonFolderResourcePack(path, spec), -// factory, -// ResourcePackProfile.InsertionPosition.BOTTOM, -// ResourcePackSource.PACK_SOURCE_BUILTIN -// )); -// } else { -// consumer.accept(ResourcePackProfile.of( -// spec.getTitle(), -// true, -// () -> new AddonResourcePack(path.toFile()), -// factory, -// ResourcePackProfile.InsertionPosition.BOTTOM, -// ResourcePackSource.PACK_SOURCE_BUILTIN -// )); -// } -// } catch (URISyntaxException e) { -// e.printStackTrace(); -// } -// }); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourcePack.java b/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourcePack.java deleted file mode 100644 index ca172da..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/client/AddonResourcePack.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.client; - -import net.minecraft.resource.ZipResourcePack; - -import java.io.File; - -public class AddonResourcePack extends ZipResourcePack { - public AddonResourcePack(File file) { - super(file); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/client/PanoramaHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/client/PanoramaHandler.java deleted file mode 100644 index 98462f4..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/client/PanoramaHandler.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.Framebuffer; -import net.minecraft.client.texture.NativeImage; -import net.minecraft.client.util.ScreenshotUtils; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.lwjgl.glfw.GLFW; -import org.sandboxpowered.sandbox.fabric.util.Log; - -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.function.Consumer; - -public class PanoramaHandler { - public static final PanoramaHandler INSTANCE = new PanoramaHandler(); - private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss"); - private File panoramaDir; - private File currentDir; - private float rotationYaw; - private float rotationPitch; - private int panoramaStep; - private boolean takingPanorama; - private int currentWidth; - private int currentHeight; - private final int panoramaSize = 1024; - private final boolean fullscreen = false; - - public void takeScreenshot(Consumer consumer) { - if (takingPanorama) - return; - - takingPanorama = true; - panoramaStep = 0; - - if (panoramaDir == null) - panoramaDir = new File("screenshots", "panoramas"); - if (!panoramaDir.exists() && !panoramaDir.mkdirs()) return; - - String ts = getTimestamp(); - do { - if (fullscreen) { - currentDir = new File(panoramaDir + "_fullres", ts); - } else { - currentDir = new File(panoramaDir, ts); - } - } while (currentDir.exists()); - - if (!currentDir.mkdirs()) return; - - Text panoramaDirComponent = new LiteralText(currentDir.getName()); - panoramaDirComponent.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, currentDir.getAbsolutePath())).withFormatting(Formatting.UNDERLINE); - consumer.accept(new LiteralText("Panorama saved as ").append(panoramaDirComponent)); - } - - public void renderTick(boolean start) { - MinecraftClient mc = MinecraftClient.getInstance(); - - if (mc.player != null && takingPanorama) { - if (start) { - if (panoramaStep == 0) { - mc.options.hudHidden = true; - currentWidth = mc.getWindow().getWidth(); - currentHeight = mc.getWindow().getHeight(); - rotationYaw = mc.player.yaw; - rotationPitch = mc.player.pitch; - - if (!fullscreen) - GLFW.glfwSetWindowSize(MinecraftClient.getInstance().getWindow().getHandle(), panoramaSize, panoramaSize); - } - - if (panoramaStep == 1) { - mc.player.yaw = 180; - mc.player.pitch = 0; - } else if (panoramaStep == 2) { - mc.player.yaw = -90; - mc.player.pitch = 0; - } else if (panoramaStep == 3) { - mc.player.yaw = 0; - mc.player.pitch = 0; - } else if (panoramaStep == 4) { - mc.player.yaw = 90; - mc.player.pitch = 0; - } else if (panoramaStep == 5) { - mc.player.yaw = 180; - mc.player.pitch = -90; - } else if (panoramaStep == 6) { - mc.player.yaw = 180; - mc.player.pitch = 90; - } - mc.player.prevYaw = mc.player.yaw; - mc.player.prevPitch = mc.player.pitch; - } else { - if (panoramaStep > 0) - saveScreenshot(currentDir, "panorama_" + (panoramaStep - 1) + ".png", mc.getWindow().getWidth(), mc.getWindow().getHeight(), mc.getFramebuffer()); - panoramaStep++; - if (panoramaStep == 7) { - mc.options.hudHidden = false; - takingPanorama = false; - - mc.player.yaw = rotationYaw; - mc.player.pitch = rotationPitch; - mc.player.prevYaw = mc.player.yaw; - mc.player.prevPitch = mc.player.pitch; - - GLFW.glfwSetWindowSize(MinecraftClient.getInstance().getWindow().getHandle(), currentWidth, currentHeight); - } - } - } - } - - private void saveScreenshot(File dir, String screenshotName, int width, int height, Framebuffer buffer) { - try { - NativeImage bufferedImage = ScreenshotUtils.takeScreenshot(width, height, buffer); - File file2 = new File(dir, screenshotName); - - bufferedImage.writeFile(file2); - } catch (Exception e) { - Log.error("Error saving panorama", e); - } - } - - private String getTimestamp() { - return dateFormat.format(new Date()); - } - - public boolean isTakingPanorama() { - return takingPanorama; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/config/Config.java b/src/main/java/org/sandboxpowered/sandbox/fabric/config/Config.java deleted file mode 100644 index d264c72..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/config/Config.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.config; - -import com.electronwill.nightconfig.core.file.CommentedFileConfig; - -import java.nio.file.Path; - -public class Config { - private final CommentedFileConfig fileConfig; - - public Config(Path path) { - this.fileConfig = CommentedFileConfig.builder(path).autosave().build(); - fileConfig.load(); - } - - public ConfigValue get(String path) { - return new ConfigValue<>(fileConfig, path); - } - - public void save() { - fileConfig.save(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/config/ConfigValue.java b/src/main/java/org/sandboxpowered/sandbox/fabric/config/ConfigValue.java deleted file mode 100644 index 44bc7a7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/config/ConfigValue.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.config; - -import com.electronwill.nightconfig.core.CommentedConfig; - -public class ConfigValue { - private final CommentedConfig config; - private final String path; - - public ConfigValue(CommentedConfig config, String path) { - this.config = config; - this.path = path; - } - - public T get() { - return config.get(path); - } - - public boolean getBoolean() { - return config.get(path); - } - - public int getInt() { - return config.get(path); - } - - public > V getEnum(Class enumType) { - return config.getEnum(path, enumType); - } - - public void set(T val) { - config.set(path, val); - } - - public void add(T val) { - config.add(path, val); - } - - public void setComment(String comment) { - config.setComment(path, comment); - } - - public void removeComment() { - config.removeComment(path); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/FluidStackImpl.java b/src/main/java/org/sandboxpowered/sandbox/fabric/impl/FluidStackImpl.java deleted file mode 100644 index 0cfe554..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/FluidStackImpl.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.impl; - -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.api.fluid.FluidStack; -import org.sandboxpowered.api.fluid.Fluids; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.nbt.CompoundTag; -import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; - -public class FluidStackImpl implements FluidStack { - private final Fluid fluid; - private int amount; - private CompoundTag stackTag; - - public FluidStackImpl(Fluid fluid, int amount) { - this.fluid = fluid; - this.amount = amount; - } - - public FluidStackImpl(Fluid fluid, int amount, CompoundTag tag) { - this.fluid = fluid; - this.amount = amount; - this.stackTag = tag; - } - - public FluidStackImpl(ReadableCompoundTag tag) { - this.fluid = Fluid.REGISTRY.get(Identity.of(tag.getString("Fluid"))).orElseGet(Fluids.EMPTY); - this.amount = tag.getInt("Amount"); - if (tag.contains("Tag")) - this.stackTag = tag.getCompound("Tag"); - } - - @Override - public boolean isEmpty() { - return Fluids.EMPTY.matches(fluid) || amount == 0; - } - - @Override - public Fluid getFluid() { - return fluid; - } - - @Override - public int getVolume() { - return amount; - } - - @Override - public FluidStack setVolume(int volume) { - amount = volume; - return this; - } - - @Override - public FluidStack copy() { - return new FluidStackImpl(fluid, amount, stackTag); - } - - @Override - public FluidStack shrink(int amount) { - this.amount -= Math.min(this.amount, amount); - return this; - } - - @Override - public FluidStack grow(int amount) { - this.amount += amount; - return this; - } - - @Override - public boolean hasTag() { - return stackTag != null; - } - - @Override - public CompoundTag getTag() { - return stackTag; - } - - @Override - public void setTag(CompoundTag stackTag) { - this.stackTag = stackTag; - } - - @Override - public CompoundTag getOrCreateTag() { - if (!hasTag()) - stackTag = CompoundTag.create(); - return stackTag; - } - - @Override - public CompoundTag getChildTag(String key) { - if (hasTag()) - return stackTag.getCompound(key); - return null; - } - - @Override - public CompoundTag getOrCreateChildTag(String key) { - CompoundTag tag = getOrCreateTag(); - if (!tag.contains(key)) - tag.setTag(key, CompoundTag.create()); - return tag.getCompound(key); - } - - @Override - public CompoundTag asTag() { - CompoundTag tag = CompoundTag.create(); - tag.setString("Fluid", fluid.getIdentity().toString()); - tag.setInt("Amount", amount); - if (hasTag()) - tag.setTag("Tag", this.getTag()); - return tag; - } - - @Override - public boolean isEqualTo(FluidStack stack) { - return stack.getFluid() == getFluid() && stack.getVolume() == getVolume(); - } - - @Override - public boolean areTagsEqual(FluidStack stack) { - return !hasTag() && !stack.hasTag() || getTag().equals(stack.getTag()); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/InternalServiceFabric.java b/src/main/java/org/sandboxpowered/sandbox/fabric/impl/InternalServiceFabric.java deleted file mode 100644 index 9ab00fc..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/impl/InternalServiceFabric.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.impl; - -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.EntityType; -import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShapes; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.block.Material; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.client.Client; -import org.sandboxpowered.api.component.Component; -import org.sandboxpowered.api.content.Content; -import org.sandboxpowered.api.enchantment.Enchantment; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.api.fluid.FluidStack; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.registry.Registry; -import org.sandboxpowered.api.server.Server; -import org.sandboxpowered.api.shape.Box; -import org.sandboxpowered.api.shape.Shape; -import org.sandboxpowered.api.state.Property; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Vec2i; -import org.sandboxpowered.api.util.math.Vec3i; -import org.sandboxpowered.api.util.nbt.CompoundTag; -import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; -import org.sandboxpowered.api.util.text.Text; -import org.sandboxpowered.eventhandler.EventHandler; -import org.sandboxpowered.eventhandler.ResettableEventHandler; -import org.sandboxpowered.internal.InternalService; -import org.sandboxpowered.sandbox.fabric.SandboxComponents; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.MaterialUtil; -import org.sandboxpowered.sandbox.fabric.util.PropertyUtil; -import org.sandboxpowered.sandbox.fabric.util.SandboxStorage; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.math.Vec2iImpl; - -import java.lang.invoke.*; -import java.util.function.Function; -import java.util.function.Supplier; - -@SuppressWarnings({"ConstantConditions", "unchecked"}) -public class InternalServiceFabric implements InternalService { - public static final InternalService INSTANCE = new InternalServiceFabric(); - - @Override - public Identity.Variant createVariantIdentity(Identity identity, String variant) { - return null; - } - - @Override - public Client clientInstance() { - return SandboxStorage.getClient(); - } - - @Override - public Vec2i createVec2i(int x, int y) { - return new Vec2iImpl(x, y); - } - - @Override - public Vec3i createVec3i(int x, int y, int z) { - return (Vec3i) new net.minecraft.util.math.Vec3i(x, y, z); - } - - @Override - public Identity createIdentityFromString(String name, String path) { - return (Identity) new Identifier(name, path); - } - - @Override - public Identity createIdentityFromString(String identity) { - return (Identity) new Identifier(identity); - } - - @Override - public Text createLiteralText(String text) { - return (Text) new LiteralText(text); - } - - @Override - public Text createTranslatedText(String translation) { - return (Text) new TranslatableText(translation); - } - - @Override - public Material getMaterial(String material) { - return MaterialUtil.from(material); - } - - @Override - public BlockEntity.Type blockEntityTypeFunction(Supplier s, Block[] b) { - return (BlockEntity.Type) BlockEntityType.Builder.create(() -> WrappingUtil.convert(s.get()), WrappingUtil.convert(b)).build(null); - } - - @Override - public ItemStack createItemStack(Item item, int amount) { - if (item == null || amount == 0) - return WrappingUtil.cast(net.minecraft.item.ItemStack.EMPTY, ItemStack.class); - return WrappingUtil.cast(new net.minecraft.item.ItemStack(WrappingUtil.convert(item), amount), ItemStack.class); - } - - @Override - public ItemStack createItemStackFromTag(ReadableCompoundTag tag) { - return WrappingUtil.cast(net.minecraft.item.ItemStack.fromTag(WrappingUtil.convert(tag)), ItemStack.class); - } - - - @Override - public > Registry registryFunction(Class cla) { - try { - @SuppressWarnings("UnnecessaryLocalVariable") Class generic = cla; - if (generic == Block.class) { - return getOrCreateRegistry("block", net.minecraft.util.registry.Registry.BLOCK, Block.class, net.minecraft.block.Block.class); - } else if (generic == Item.class) { - return getOrCreateRegistry("item", net.minecraft.util.registry.Registry.ITEM, Item.class, net.minecraft.item.Item.class); - } else if (generic == BlockEntity.Type.class) { - return getOrCreateRegistry("block_entity_type", net.minecraft.util.registry.Registry.BLOCK_ENTITY_TYPE, BlockEntity.Type.class, BlockEntityType.class); - } else if (generic == Fluid.class) { - return getOrCreateRegistry("fluid", net.minecraft.util.registry.Registry.FLUID, Fluid.class, net.minecraft.fluid.Fluid.class); - } else if (generic == Enchantment.class) { - return getOrCreateRegistry("enchantment", net.minecraft.util.registry.Registry.ENCHANTMENT, Enchantment.class, net.minecraft.enchantment.Enchantment.class); - } else if (generic == Entity.Type.class) { - return getOrCreateRegistry("entity_type", net.minecraft.util.registry.Registry.ENTITY_TYPE, Entity.Type.class, EntityType.class); - } - } catch (Throwable throwable) { - throw new IllegalArgumentException("Unknown registry " + cla, throwable); - } - return null; - } - - private , V, T extends Content> Registry getOrCreateRegistry(String name, net.minecraft.util.registry.Registry vRegistry, Class sClass, Class vClass) throws Throwable { - SandboxInternal.Registry sRegistry = (SandboxInternal.Registry) vRegistry; - Registry registry = sRegistry.sandboxGet(); - if (registry == null) { - MethodHandles.Lookup lookup = MethodHandles.lookup(); - MethodHandle handleSV = lookup.findStatic(WrappingUtil.class, "convert", MethodType.methodType(vClass, sClass)); - MethodHandle handleVS = lookup.findStatic(WrappingUtil.class, "convert", MethodType.methodType(sClass, vClass)); - Function convertSV = (Function) LambdaMetafactory.metafactory(lookup, "apply", MethodType.methodType(Function.class), MethodType.methodType(Object.class, Object.class), handleSV, handleSV.type()).getTarget().invokeExact(); - Function convertVS = (Function) LambdaMetafactory.metafactory(lookup, "apply", MethodType.methodType(Function.class), MethodType.methodType(Object.class, Object.class), handleVS, handleVS.type()).getTarget().invokeExact(); - sRegistry.sandboxSet(new WrappedRegistry<>(Identity.of(name), vRegistry, sClass, convertSV, convertVS)); - registry = sRegistry.sandboxGet(); - } - //Force cast to T at the end to return the type needed - return (Registry) registry; - } - - @Override - public CompoundTag createCompoundTag() { - return (CompoundTag) new net.minecraft.nbt.CompoundTag(); - } - - @Override - public Server serverInstance() { - return SandboxStorage.getServer(); - } - - @Override - public Position createPosition(int x, int y, int z) { - return (Position) new net.minecraft.util.math.BlockPos(x, y, z); - } - - @Override - public Position.Mutable createMutablePosition(int x, int y, int z) { - return (Position.Mutable) new BlockPos.Mutable(x, y, z); - } - - @Override - public > Property getProperty(String property) { - return PropertyUtil.get(property); - } - - @Override - public Component componentFunction(Class c) { - return SandboxComponents.getComponent(c); - } - - @Override - public Entity.Type entityTypeEntityFunction(Entity e) { - return (Entity.Type) EntityType.fromTag(WrappingUtil.convert(e).toTag(new net.minecraft.nbt.CompoundTag())).orElse(null); - } - - @Override - public FluidStack fluidStackFunction(Fluid fluid, int amount) { - return new FluidStackImpl(fluid, amount); - } - - @Override - public FluidStack fluidStackFromTagFunction(ReadableCompoundTag tag) { - return new FluidStackImpl(tag); - } - - @Override - public Shape shape_cube(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - return WrappingUtil.convert(VoxelShapes.cuboid(minX, minY, minZ, maxX, maxY, maxZ)); - } - - @Override - public Shape shape_fullCube() { - return WrappingUtil.convert(VoxelShapes.fullCube()); - } - - @Override - public Shape shape_empty() { - return WrappingUtil.convert(VoxelShapes.empty()); - } - - @Override - public EventHandler createEventHandler() { - return new ResettableEventHandler<>(); - } - - @Override - public Box box_of(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - return WrappingUtil.convert(new net.minecraft.util.math.Box(minX, minY, minZ, maxX, maxY, maxZ)); - } - - @Override - public Box box_of(Position pos1, Position pos2) { - return WrappingUtil.convert(new net.minecraft.util.math.Box(WrappingUtil.convert(pos1), WrappingUtil.convert(pos2))); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ClientConnectionInternal.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ClientConnectionInternal.java deleted file mode 100644 index 8eed838..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ClientConnectionInternal.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import com.mojang.authlib.properties.Property; - -import java.net.SocketAddress; -import java.util.UUID; - -public interface ClientConnectionInternal { - void setSocketAddress(SocketAddress address); - - UUID getSandboxUUID(); - - void setSandboxUUID(UUID uuid); - - Property[] getSandboxProfile(); - - void setSandboxProfile(Property[] profile); -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/CustomPayloadPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/CustomPayloadPacket.java deleted file mode 100644 index 7d53e77..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/CustomPayloadPacket.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; - -public interface CustomPayloadPacket { - Identifier channel(); - - PacketByteBuf data(); - - interface LoginQueryPacket { - int getQueryId(); - - PacketByteBuf getBuffer(); - } - - interface Handshake { - String getPassword(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/IFrustumWorldRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/IFrustumWorldRenderer.java deleted file mode 100644 index a1e1645..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/IFrustumWorldRenderer.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import net.minecraft.client.render.Frustum; - -public interface IFrustumWorldRenderer { - Frustum sandboxGetFrustum(); -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandbox.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandbox.java deleted file mode 100644 index 986b0ea..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandbox.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import org.sandboxpowered.api.util.Side; - -public interface ISandbox { - - Side getSide(); -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandboxScreen.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandboxScreen.java deleted file mode 100644 index c01df60..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/ISandboxScreen.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import net.minecraft.client.gui.widget.AbstractButtonWidget; - -import java.util.List; - -public interface ISandboxScreen { - List getButtons(); -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/LoginQueryRequestPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/LoginQueryRequestPacket.java deleted file mode 100644 index bf943d9..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/LoginQueryRequestPacket.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; - -public interface LoginQueryRequestPacket { - void setQueryId(int queryId); - - void setChannel(Identifier channel); - - void setPayload(PacketByteBuf payload); -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/SandboxInternal.java b/src/main/java/org/sandboxpowered/sandbox/fabric/internal/SandboxInternal.java deleted file mode 100644 index 96c125c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/internal/SandboxInternal.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.internal; - -import net.minecraft.client.texture.Sprite; -import net.minecraft.util.registry.RegistryKey; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.content.Content; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.state.PropertyContainer; -import org.sandboxpowered.sandbox.fabric.impl.WrappedRegistry; - -public class SandboxInternal { - - public interface StateFactory> { - org.sandboxpowered.api.state.StateFactory getSboxFactory(); - - void setSboxFactory(org.sandboxpowered.api.state.StateFactory factory); - } - - public interface StateFactoryBuilder> { - org.sandboxpowered.api.state.StateFactory.Builder getSboxBuilder(); - - void setSboxBuilder(org.sandboxpowered.api.state.StateFactory.Builder builder); - } - - public interface Registry, B> { - void sandboxStore(); - - void sandboxReset(); - - void sandboxSet(WrappedRegistry registry); - - WrappedRegistry sandboxGet(); - } - - public interface RegistryKeyObtainer { - RegistryKey> sandboxGetRegistryKey(); - } - - public interface IItemWrapper { - Item getItem(); - } - - public interface IBlockWrapper { - Block getBlock(); - } - - public interface MaterialInternal { - void setLevel(int level); - } - - public interface BaseFluid { - boolean sandboxInfinite(); - } - - public interface WrappedInjection { - T getInjectionWrapped(); - - void setInjectionWrapped(T o); - } - - public interface StateFactoryHolder> { - org.sandboxpowered.api.state.StateFactory getSandboxStateFactory(); - } - - public interface MagicSprite { - void markActive(); - } - - public interface MagicQuad { - Sprite getSprite(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/loader/SandboxLoader.java b/src/main/java/org/sandboxpowered/sandbox/fabric/loader/SandboxLoader.java deleted file mode 100644 index 9d1a44b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/loader/SandboxLoader.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.loader; - -import com.electronwill.nightconfig.core.Config; -import com.electronwill.nightconfig.toml.TomlParser; -import net.fabricmc.loader.util.UrlConversionException; -import net.fabricmc.loader.util.UrlUtil; -import net.minecraft.util.registry.Registry; -import org.apache.commons.io.IOUtils; -import org.sandboxpowered.api.addon.Addon; -import org.sandboxpowered.internal.AddonSpec; -import org.sandboxpowered.sandbox.fabric.SandboxFabric; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.security.AddonClassLoader; -import org.sandboxpowered.sandbox.fabric.util.Log; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.jar.JarFile; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.zip.ZipEntry; - -public class SandboxLoader { - private static final String SANDBOX_TOML = "sandbox.toml"; - public static SandboxLoader loader; - private final Map modidToLoader = new LinkedHashMap<>(); - private SandboxFabric fabric; - - public SandboxLoader() { - loader = this; - } - - public SandboxFabric getFabric() { - return fabric; - } - - public void load() throws IOException { - if (fabric != null) - fabric.destroy(); - fabric = new SandboxFabric(); - modidToLoader.clear(); - - Registry.REGISTRIES.stream().map(registry -> (SandboxInternal.Registry) registry).forEach(SandboxInternal.Registry::sandboxStore); - - Path addonPath = Paths.get("addons"); - if (Files.notExists(addonPath)) Files.createDirectories(addonPath); - Set addonUrls; - try (Stream stream = Files.walk(addonPath, 1)) { - addonUrls = stream.filter(path -> path.toString().endsWith(".jar")) - .map(path -> { - try { - return path.toUri().toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - }).collect(Collectors.toSet()); - } - - Enumeration enumeration = getClass().getClassLoader().getResources(SANDBOX_TOML); - while (enumeration.hasMoreElements()) { // Add it all to a set to temporarily remove duplicates - try { - addonUrls.add(UrlUtil.getSource(SANDBOX_TOML, enumeration.nextElement())); - } catch (UrlConversionException e) { - Log.error("Error converting URL", e); - } - } - - if (addonUrls.isEmpty()) { - Log.info("Loaded 0 addons"); - } else { - Log.info("Loading %d addons", addonUrls.size()); - TomlParser parser = new TomlParser(); - for (URL cURL : addonUrls) { - InputStream configStream = null; - try { - if (cURL.toString().endsWith(".jar")) { - try (JarFile jarFile = new JarFile(new File(cURL.toURI()))) { - ZipEntry ze = jarFile.getEntry(SANDBOX_TOML); - if (ze != null) - configStream = jarFile.getInputStream(ze); - } - } else { - configStream = cURL.toURI().resolve(SANDBOX_TOML).toURL().openStream(); - } - if (configStream == null) - continue; - Config config = parser.parse(configStream); - AddonSpec spec = AddonSpec.from(config, cURL); - getClassLoader(spec).addURL(cURL); - Class mainClass = getClassLoader(spec).loadClass(spec.getMainClass()); - if (Addon.class.isAssignableFrom(mainClass)) { - Addon addon = (Addon) mainClass.getConstructor().newInstance(); - fabric.loadAddon(spec, addon); - } - } catch (Exception e) { - Log.error("Unknown Error", e); - } finally { - IOUtils.closeQuietly(configStream); - } - } - - fabric.initAll(); - fabric.registerAll(); - fabric.reloadResources(); - } - } - - public AddonClassLoader getClassLoader(AddonSpec spec) { - return modidToLoader.computeIfAbsent(spec.getId(), addonId -> new AddonClassLoader(getClass().getClassLoader(), spec)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/block/MixinAnvilBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/block/MixinAnvilBlock.java deleted file mode 100644 index 4456b95..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/block/MixinAnvilBlock.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.block; - -import net.minecraft.block.AnvilBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.FallingBlock; -import net.minecraft.entity.FallingBlockEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.world.World; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.events.EntityEvents; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; -import java.util.stream.Collectors; - -@Mixin(AnvilBlock.class) -public abstract class MixinAnvilBlock extends FallingBlock { - public MixinAnvilBlock(Settings settings) { - super(settings); - } - - @Inject(method = "onLanding", at = @At(value = "RETURN")) - public void onLanding(World world, BlockPos pos, BlockState fallState, BlockState hitState, FallingBlockEntity entity, CallbackInfo ci) { - if (EntityEvents.ANVIL_FALL.hasSubscribers()) { - List entities = world.getOtherEntities(null, new Box(pos, pos.add(1, 1, 1))) - .stream().map(WrappingUtil::convert).collect(Collectors.toList()); - org.sandboxpowered.api.world.World sbxWorld = WrappingUtil.convert(world); - org.sandboxpowered.api.util.math.Position sbxPos = WrappingUtil.convert(pos); - org.sandboxpowered.api.state.BlockState sbxFall = WrappingUtil.convert(fallState); - org.sandboxpowered.api.state.BlockState sbxHit = WrappingUtil.convert(hitState); - org.sandboxpowered.api.entity.Entity sbxEnt = WrappingUtil.convert(entity); - - EntityEvents.ANVIL_FALL.post(event -> event.onEvent(sbxWorld, sbxPos, sbxFall, sbxHit, sbxEnt, entities)); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinMinecraftClient.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinMinecraftClient.java deleted file mode 100644 index 5fa2009..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinMinecraftClient.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(MinecraftClient.class) -public class MixinMinecraftClient { - - @Shadow - @Nullable - public Screen currentScreen; - -// @ModifyVariable(method = "openScreen", at = @At("HEAD"), ordinal = 0) -// public Screen openScreen(Screen screen) { -// if (screen == null) { -// ScreenEvent.Close close = EventDispatcher.publish(new ScreenEvent.Close(WrappingUtil.convert(currentScreen))); -// if (close.isCancelled()) -// return currentScreen; -// return null; -// } else { -// ScreenEvent.Open open = EventDispatcher.publish(new ScreenEvent.Open(WrappingUtil.convert(screen))); -// if (open.isCancelled()) -// return currentScreen; -// return WrappingUtil.convert(open.getScreen()); -// } -// } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinWorldRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinWorldRenderer.java deleted file mode 100644 index c5f3dbf..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/client/MixinWorldRenderer.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.client; - -import net.minecraft.client.render.*; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.math.Matrix4f; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.profiler.Profiler; -import org.sandboxpowered.api.client.rendering.events.RenderEvents; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(WorldRenderer.class) -public class MixinWorldRenderer { - @Shadow - private ClientWorld world; - - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;checkEmpty(Lnet/minecraft/client/util/math/MatrixStack;)V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD) - public void render(MatrixStack matrixStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci, Profiler profiler, Vec3d vec3d, double d, double e, double g, Matrix4f matrix4f2, boolean bl2, Frustum frustum2, boolean bl4, VertexConsumerProvider.Immediate immediate) { - matrixStack.push(); - matrixStack.translate(-d, -e, -g); - - if (RenderEvents.RENDER_IN_WORLD.hasSubscribers()) { - World sbxWorld = WrappingUtil.convert(this.world); - org.sandboxpowered.api.util.math.MatrixStack sbxStack = WrappingUtil.convert(matrixStack); - org.sandboxpowered.api.client.rendering.VertexConsumer.Provider sbxProvider = WrappingUtil.convert(immediate); - RenderEvents.RENDER_IN_WORLD.post(event -> event.onEvent(sbxWorld, sbxStack, sbxProvider)); - } - - matrixStack.pop(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/enchant/MixinEnchantment.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/enchant/MixinEnchantment.java deleted file mode 100644 index 9bc7843..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/enchant/MixinEnchantment.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.enchant; - -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(net.minecraft.enchantment.Enchantment.class) -public abstract class MixinEnchantment { - - @Inject(method = "isAcceptableItem(Lnet/minecraft/item/ItemStack;)Z", at = @At(value = "HEAD"), cancellable = true) - public void isAcceptableItem(ItemStack stack, CallbackInfoReturnable info) { -// EnchantmentEvent.AcceptableItem event = EventDispatcher.publish(new EnchantmentEvent.AcceptableItem((Enchantment) this, WrappingUtil.cast(stack, org.sandboxpowered.api.item.ItemStack.class))); -// if (event.getResult() != EventResult.IGNORE) { -// info.setReturnValue(event.getResult() == EventResult.SUCCESS); -// } - } - - @Inject(method = "canAccept(Lnet/minecraft/enchantment/Enchantment;)Z", at = @At(value = "HEAD"), cancellable = true) - public void isDifferent(net.minecraft.enchantment.Enchantment other, CallbackInfoReturnable info) { -// EnchantmentEvent.Compatible event = EventDispatcher.publish(new EnchantmentEvent.Compatible((Enchantment) this, (Enchantment) other)); -// if (event.getResult() != EventResult.IGNORE) { -// info.setReturnValue(event.getResult() == EventResult.SUCCESS); -// } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinFallingBlockEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinFallingBlockEntity.java deleted file mode 100644 index 5118503..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinFallingBlockEntity.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.FallingBlockEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(FallingBlockEntity.class) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinFallingBlockEntity extends Entity { - public MixinFallingBlockEntity(EntityType type, World world) { - super(type, world); - } - -// @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FallingBlock;onLanding(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V")) -// public void onLand(FallingBlock block, World world_1, BlockPos pos, BlockState state, BlockState blockState_2) { -//// EventDispatcher.publish(new BlockEvent.Fall( -//// (org.sandboxpowered.api.world.World) world_1, -//// WrappingUtil.convert(pos), -//// (org.sandboxpowered.api.state.BlockState) state, -//// fallDistance)); -// block.onLanding(world_1, pos, state, blockState_2); -// } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLightningEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLightningEntity.java deleted file mode 100644 index 8d47590..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLightningEntity.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LightningEntity; -import net.minecraft.world.World; -import org.sandboxpowered.api.events.WorldEvents; -import org.sandboxpowered.api.util.math.Vec3d; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.List; -import java.util.stream.Collectors; - -@Mixin(LightningEntity.class) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinLightningEntity extends Entity { - private boolean attemptedEvent; - - public MixinLightningEntity(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "tick", at = @At( - value = "INVOKE_ASSIGN", - target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;", - ordinal = 0, shift = At.Shift.BY, by = 1 - ), locals = LocalCapture.CAPTURE_FAILHARD) - public void handleLightning(CallbackInfo ci, double d0, List list) { - if (attemptedEvent) return; - - if (WorldEvents.LIGHTNING_STRIKE.hasSubscribers()) { - org.sandboxpowered.api.world.World world = WrappingUtil.convert(getEntityWorld()); - Vec3d pos = WrappingUtil.convert(getPos()); - List sbxList = list.stream().map(WrappingUtil::convert).collect(Collectors.toList()); - WorldEvents.LIGHTNING_STRIKE.post(event -> event.onEvent(world, pos, sbxList)); - } - - attemptedEvent = true; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLivingEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLivingEntity.java deleted file mode 100644 index edbc259..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinLivingEntity.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(net.minecraft.entity.LivingEntity.class) -public abstract class MixinLivingEntity extends Entity { - public MixinLivingEntity(EntityType type, World world) { - super(type, world); - } - - @Inject(method = "onDeath", at = @At("HEAD"), cancellable = true) - public void onDeath(DamageSource source, CallbackInfo info) { -// LivingEvent.Death event = EventDispatcher.publish(new LivingEvent.Death((LivingEntity) this)); -// if (event.isCancelled()) -// info.cancel(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerEntity.java deleted file mode 100644 index 06bca13..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerEntity.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import org.sandboxpowered.api.events.ItemEvents; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(PlayerEntity.class) -public abstract class MixinPlayerEntity extends net.minecraft.entity.LivingEntity { - - public MixinPlayerEntity(EntityType entityType, World world) { - super(entityType, world); - } - - /** - * @author Coded - */ - @Inject(method = "getArrowType", at = @At("RETURN"), cancellable = true) - public void getModifiedArrowType(ItemStack weapon, CallbackInfoReturnable info) { - if (ItemEvents.GET_ARROW_TYPE.hasSubscribers()) { - org.sandboxpowered.api.entity.player.PlayerEntity player = WrappingUtil.convert((PlayerEntity) (Object) this); - org.sandboxpowered.api.item.ItemStack sWeapon = WrappingUtil.convert(weapon); - org.sandboxpowered.api.item.ItemStack originalArrow = WrappingUtil.convert(weapon); - org.sandboxpowered.api.item.ItemStack s = ItemEvents.GET_ARROW_TYPE.post( - (event, value) -> event.onEvent(player, sWeapon, value), - originalArrow - ); - if (!s.isEmpty()) - info.setReturnValue(WrappingUtil.convert(s)); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerInventory.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerInventory.java deleted file mode 100644 index 4a561e8..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinPlayerInventory.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.events.ItemEvents; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(PlayerInventory.class) -public class MixinPlayerInventory { - - @Shadow - @Final - public net.minecraft.entity.player.PlayerEntity player; - - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMiningSpeedMultiplier(Lnet/minecraft/block/BlockState;)F"), method = "getBlockBreakingSpeed") - public float getMiningSpeedMultiplier(ItemStack originalStack, BlockState originalState) { - float miningSpeed = originalStack.getMiningSpeedMultiplier(originalState); - if (ItemEvents.MINING_SPEED.hasSubscribers()) { - org.sandboxpowered.api.item.ItemStack stack = WrappingUtil.convert(originalStack); - org.sandboxpowered.api.state.BlockState state = WrappingUtil.convert(originalState); - PlayerEntity player = WrappingUtil.convert(this.player); - miningSpeed = ItemEvents.MINING_SPEED.post((event, speed) -> event.onEvent(player, stack, state, speed), miningSpeed); - } - return miningSpeed; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinServerPlayerEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinServerPlayerEntity.java deleted file mode 100644 index 9fb849d..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/entity/MixinServerPlayerEntity.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.entity; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ServerPlayerEntity.class) -public abstract class MixinServerPlayerEntity extends net.minecraft.entity.LivingEntity { - public MixinServerPlayerEntity(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "onDeath", at = @At("HEAD"), cancellable = true) - public void onDeath(DamageSource source, CallbackInfo info) { -// LivingEvent.Death event = EventDispatcher.publish(new LivingEvent.Death((LivingEntity) this)); -// if (event.isCancelled()) -// info.cancel(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinBlockItem.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinBlockItem.java deleted file mode 100644 index 22a187b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinBlockItem.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.item; - -import net.minecraft.block.BlockState; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.util.math.BlockPos; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.events.BlockEvents; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.eventhandler.Cancellable; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.concurrent.atomic.AtomicReference; - -@Mixin(BlockItem.class) -public abstract class MixinBlockItem { - private final AtomicReference stateReference = new AtomicReference<>(); - - @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", - at = @At(value = "HEAD"), cancellable = true - ) - public void place(ItemPlacementContext context, BlockState state, CallbackInfoReturnable info) { - if (BlockEvents.PLACE.hasSubscribers()) { - Cancellable cancellable = new Cancellable(); - World world = WrappingUtil.convert(context.getWorld()); - Position pos = WrappingUtil.convert(context.getBlockPos()); - org.sandboxpowered.api.state.BlockState originalState = WrappingUtil.convert(state); - PlayerEntity player = WrappingUtil.convert(context.getPlayer()); - ItemStack stack = WrappingUtil.convert(context.getStack()); - org.sandboxpowered.api.state.BlockState retState = BlockEvents.PLACE.post( - (event, value) -> event.onEvent(world, pos, value, player, stack, cancellable), - originalState, - cancellable - ); - if (cancellable.isCancelled()) info.setReturnValue(false); - else stateReference.set(WrappingUtil.convert(retState)); - } else { - stateReference.set(state); - } - } - - @Redirect(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z") - ) - public boolean setBlockState(net.minecraft.world.World world, BlockPos blockPos, BlockState blockState, int i) { - BlockState state = stateReference.getAndSet(null); - if (state != null) - return world.setBlockState(blockPos, state, i); - return world.setBlockState(blockPos, blockState, i); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinItemStack.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinItemStack.java deleted file mode 100644 index 7416de6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/item/MixinItemStack.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.item; - -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayerEntity; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.events.ItemEvents; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import javax.annotation.Nullable; -import java.util.Random; - -@Mixin(ItemStack.class) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinItemStack { - @Shadow - public abstract boolean isDamageable(); - - @ModifyVariable(method = "damage(ILjava/util/Random;Lnet/minecraft/server/network/ServerPlayerEntity;)Z", at = @At(value = "LOAD", ordinal = 0)) - public int place(int localDamage, int damage, Random rdm, @Nullable ServerPlayerEntity playerEntity) { - if (isDamageable()) - return localDamage; - if (ItemEvents.DAMAGE.hasSubscribers()) { - PlayerEntity player = WrappingUtil.convert(playerEntity); - org.sandboxpowered.api.item.ItemStack stack = WrappingUtil.convert((ItemStack) (Object) this); - return ItemEvents.DAMAGE.post((event, value) -> event.onEvent(player, stack, value), damage); - } - return localDamage; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinClientPlayerInteractionManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinClientPlayerInteractionManager.java deleted file mode 100644 index 95c2fc8..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinClientPlayerInteractionManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.network; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.events.BlockEvents; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.eventhandler.Cancellable; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(ClientPlayerInteractionManager.class) -public class MixinClientPlayerInteractionManager { - - @Shadow - @Final - private MinecraftClient client; - - @Shadow @Final private ClientPlayNetworkHandler networkHandler; - - @Inject(method = "breakBlock", at = @At("HEAD"), cancellable = true) - public void breakBlock(BlockPos pos, CallbackInfoReturnable info) { - if (BlockEvents.BREAK.hasSubscribers()) { - Cancellable cancellable = new Cancellable(); - World world = WrappingUtil.convert(this.client.world); - Position position = WrappingUtil.convert(pos); - BlockState state = WrappingUtil.convert(this.client.world.getBlockState(pos)); - PlayerEntity player = WrappingUtil.convert(this.client.player); - ItemStack tool = player.getHeld(Hand.MAIN_HAND); - - BlockEvents.BREAK.post(breakEvent -> breakEvent.onEvent(world, position, state, player, tool, cancellable), cancellable); - if (cancellable.isCancelled()) { - info.setReturnValue(false); - } - } - } - - @Inject(method = "interactBlock", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/util/hit/BlockHitResult;getBlockPos()Lnet/minecraft/util/math/BlockPos;"), cancellable = true) - public void interactBlock(ClientPlayerEntity clientPlayerEntity, ClientWorld clientWorld, net.minecraft.util.Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable info) { - if (BlockEvents.INTERACT.hasSubscribers()) { - World sandWorld = WrappingUtil.convert(clientWorld); - Position position = WrappingUtil.convert(blockHitResult.getBlockPos()); - BlockState sandState = sandWorld.getBlockState(position); - PlayerEntity sandPlayer = WrappingUtil.convert(clientPlayerEntity); - Hand sandHand = WrappingUtil.convert(hand); - ItemStack tool = sandPlayer.getHeld(sandHand); - - InteractionResult result = BlockEvents.INTERACT.post((event, res) -> event.onEvent(sandWorld, position, sandState, sandPlayer, sandHand, tool, res), InteractionResult.IGNORE); - - if (result != InteractionResult.IGNORE) { - this.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(hand, blockHitResult)); - info.setReturnValue(WrappingUtil.convert(result)); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinServerPlayerInteractionManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinServerPlayerInteractionManager.java deleted file mode 100644 index a5ed701..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/network/MixinServerPlayerInteractionManager.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.network; - -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.network.ServerPlayerInteractionManager; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.events.BlockEvents; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.eventhandler.Cancellable; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(ServerPlayerInteractionManager.class) -public class MixinServerPlayerInteractionManager { - - @Shadow - public ServerWorld world; - - @Shadow - public ServerPlayerEntity player; - - @Inject(method = "tryBreakBlock", at = @At("HEAD"), cancellable = true) - public void tryBreakBlock(BlockPos pos, CallbackInfoReturnable info) { - if (BlockEvents.BREAK.hasSubscribers()) { - Cancellable cancellable = new Cancellable(); - World world = WrappingUtil.convert(this.world); - Position position = WrappingUtil.convert(pos); - BlockState state = WrappingUtil.convert(this.world.getBlockState(pos)); - PlayerEntity player = WrappingUtil.convert(this.player); - ItemStack tool = player.getHeld(Hand.MAIN_HAND); - - BlockEvents.BREAK.post(breakEvent -> breakEvent.onEvent(world, position, state, player, tool, cancellable), cancellable); - if (cancellable.isCancelled()) { - info.setReturnValue(false); - } - } - } - - @Inject(method = "interactBlock", at = @At(value = "HEAD"), cancellable = true) - public void interactBlock(ServerPlayerEntity serverPlayerEntity, net.minecraft.world.World world, net.minecraft.item.ItemStack itemStack, net.minecraft.util.Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable info) { - if (BlockEvents.INTERACT.hasSubscribers()) { - World sandWorld = WrappingUtil.convert(world); - Position position = WrappingUtil.convert(blockHitResult.getBlockPos()); - BlockState sandState = sandWorld.getBlockState(position); - PlayerEntity sandPlayer = WrappingUtil.convert(serverPlayerEntity); - ItemStack tool = WrappingUtil.convert(itemStack); - Hand sandHand = WrappingUtil.convert(hand); - - InteractionResult result = BlockEvents.INTERACT.post((event, res) -> event.onEvent(sandWorld, position, sandState, sandPlayer, sandHand, tool, res), InteractionResult.IGNORE); - - if (result != InteractionResult.IGNORE) { - info.setReturnValue(WrappingUtil.convert(result)); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinBlockCollisionSpliterator.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinBlockCollisionSpliterator.java deleted file mode 100644 index fd56c77..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinBlockCollisionSpliterator.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.world; - -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Box; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockCollisionSpliterator; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.events.WorldEvents; -import org.sandboxpowered.api.shape.Shape; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Spliterator; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; - -@Mixin(BlockCollisionSpliterator.class) -public class MixinBlockCollisionSpliterator { - @Shadow - @Final - private Box box; - @Shadow - @Final - private @Nullable Entity entity; - private boolean sandboxShouldAlterCollisionBoxes; - private Spliterator sandboxShapes; - - @Inject(method = "(Lnet/minecraft/world/CollisionView;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/BiPredicate;)V", at = @At("RETURN")) - public void constructor(CallbackInfo info) { - if (WorldEvents.ADD_COLLISION_BOXES.hasSubscribers()) { - sandboxShouldAlterCollisionBoxes = true; - org.sandboxpowered.api.entity.Entity sandboxEnt = WrappingUtil.convert(this.entity); - List shapes = new ArrayList<>(); - sandboxShapes = WorldEvents.ADD_COLLISION_BOXES.post((event, original) -> event.getShapes(sandboxEnt, original), shapes).spliterator(); - } - } - - @Inject(method = "offerBlockShape", at = @At("RETURN"), cancellable = true) - public void offerShape(Consumer consumer, CallbackInfoReturnable info) { - if (sandboxShouldAlterCollisionBoxes&&!info.getReturnValue()) { - AtomicReference ref = new AtomicReference<>(); - while (true) { - if (sandboxShapes.tryAdvance(ref::set)) { - VoxelShape area = WrappingUtil.convert(ref.get()); - if (!area.isEmpty() && area.getBoundingBox().intersects(this.box)) { - consumer.accept(area); - info.setReturnValue(true); - return; - } - } else { - return; - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinServerWorld.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinServerWorld.java deleted file mode 100644 index 88bfecb..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/event/world/MixinServerWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.event.world; - -import net.minecraft.entity.Entity; -import net.minecraft.server.world.ServerWorld; -import org.sandboxpowered.api.events.EntityEvents; -import org.sandboxpowered.eventhandler.Cancellable; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ServerWorld.class) -public class MixinServerWorld { - @Inject(method = "addEntity", - at = @At(value = "HEAD"), - cancellable = true - ) - public void addEntity(Entity entity, CallbackInfoReturnable info) { - if (EntityEvents.SPAWN.hasSubscribers()) { - org.sandboxpowered.api.entity.Entity ent = WrappingUtil.convert(entity); - Cancellable cancellable = new Cancellable(); - -// EntityEvents.SPAWN.post(event -> event.onEvent(ent), cancellable); - - if (cancellable.isCancelled()) - info.setReturnValue(false); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/MixinBootstrap.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/MixinBootstrap.java deleted file mode 100644 index 9da5cdb..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/MixinBootstrap.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric; - -import net.minecraft.Bootstrap; -import org.sandboxpowered.sandbox.fabric.SandboxHooks; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = Bootstrap.class) -public class MixinBootstrap { - @Shadow - private static boolean initialized; - - @Inject(method = "initialize", at = @At("HEAD")) - private static void init(CallbackInfo info) { - if (!initialized) { - SandboxHooks.setupGlobal(); - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlock.java deleted file mode 100644 index ded5a8a..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.block; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.AbstractBlock.Settings; -import net.minecraft.block.BlockState; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.state.property.Properties; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.function.ToIntFunction; - -@Mixin(AbstractBlock.class) -public class MixinBlock { - - /** - * @author B0undarybreaker - */ - @Inject(method = "getFluidState", at = @At("HEAD"), cancellable = true) - private void getWaterloggedFluidState(BlockState state, CallbackInfoReturnable info) { - if (state.contains(Properties.WATERLOGGED)) - info.setReturnValue(state.get(Properties.WATERLOGGED) ? Fluids.WATER.getDefaultState() : Fluids.EMPTY.getDefaultState()); - } - - @Mixin(Settings.class) - public abstract static class MixinSettings implements SandboxInternal.MaterialInternal { - - @Shadow public abstract Settings luminance(ToIntFunction toIntFunction); - - @Override - public void setLevel(int level) { - luminance(state -> level); - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlockState.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlockState.java deleted file mode 100644 index 0321096..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinBlockState.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.block; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.BlockState; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.WorldAccess; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(AbstractBlock.AbstractBlockState.class) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinBlockState { - - @Shadow - public abstract FluidState getFluidState(); - - @SuppressWarnings("ConstantConditions") - @Inject(at = @At("RETURN"), method = "getLuminance", cancellable = true) - public void onGetLuminance(CallbackInfoReturnable info) { - FluidState fluidState = getFluidState(); - if (fluidState.getFluid() != Fluids.EMPTY) { - BlockState fluidBlockState = fluidState.getBlockState(); - if (fluidBlockState != (Object) this) { - info.setReturnValue(Math.max(info.getReturnValue(), fluidBlockState.getLuminance())); - } - } - } - - @Inject(at = @At("HEAD"), method = "getStateForNeighborUpdate") - public void onGetStateForNeighborUpdate(Direction direction, BlockState state, WorldAccess world, BlockPos pos, BlockPos otherPos, CallbackInfoReturnable info) { - FluidState fluidState = getFluidState(); - if (!fluidState.isEmpty()) { - world.getFluidTickScheduler().schedule(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world)); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinStateManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinStateManager.java deleted file mode 100644 index 64ec6b3..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/block/MixinStateManager.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.block; - -import net.minecraft.state.State; -import org.sandboxpowered.api.state.PropertyContainer; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.wrapper.StateFactoryImpl; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(net.minecraft.state.StateManager.class) -public abstract class MixinStateManager> implements SandboxInternal.StateFactory { - private StateFactory sandboxFactory; - - @Override - public StateFactory getSboxFactory() { - return sandboxFactory; - } - - @Override - public void setSboxFactory(StateFactory factory) { - this.sandboxFactory = factory; - } - - @Mixin(net.minecraft.state.StateManager.Builder.class) - public static abstract class MixinStateBuilder & PropertyContainer> implements SandboxInternal.StateFactoryBuilder { - private StateFactory.Builder sandboxBuilder; - - @SuppressWarnings("unchecked") - private static B cast(A a) { - return (B) a; - } - - @Inject(method = "", at = @At("RETURN")) - public void inject(CallbackInfo info) { - setSboxBuilder(new StateFactoryImpl.BuilderImpl<>(cast(this))); - } - - @Override - public StateFactory.Builder getSboxBuilder() { - return sandboxBuilder; - } - - @Override - public void setSboxBuilder(StateFactory.Builder builder) { - sandboxBuilder = builder; - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameOptions.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameOptions.java deleted file mode 100644 index 9e00cfc..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameOptions.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.options.GameOptions; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(GameOptions.class) -public class MixinGameOptions { - @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/options/GameOptions;load()V")) - public void defaultOptions(GameOptions options) { - options.autoJump = false; - - options.load(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameRenderer.java deleted file mode 100644 index 95c6c46..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinGameRenderer.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.render.GameRenderer; -import org.sandboxpowered.sandbox.fabric.client.PanoramaHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(GameRenderer.class) -public class MixinGameRenderer { - @Inject(method = "getFov", - at = @At("HEAD"), - cancellable = true - ) - public void getFov(CallbackInfoReturnable info) { - if (PanoramaHandler.INSTANCE.isTakingPanorama()) - info.setReturnValue(90.0D); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinIntegratedServer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinIntegratedServer.java deleted file mode 100644 index dca1a39..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinIntegratedServer.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import com.mojang.authlib.GameProfileRepository; -import com.mojang.authlib.minecraft.MinecraftSessionService; -import com.mojang.datafixers.DataFixer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.resource.ResourcePackManager; -import net.minecraft.resource.ServerResourceManager; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.WorldGenerationProgressListenerFactory; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.util.UserCache; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.SaveProperties; -import net.minecraft.world.level.storage.LevelStorage; -import org.sandboxpowered.api.client.Client; -import org.sandboxpowered.api.server.Server; -import org.sandboxpowered.sandbox.fabric.loader.SandboxLoader; -import org.sandboxpowered.sandbox.fabric.util.SandboxStorage; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.IOException; -import java.net.Proxy; - -@Mixin(IntegratedServer.class) -public abstract class MixinIntegratedServer extends MinecraftServer { - @Shadow - @Final - private MinecraftClient client; - - public MixinIntegratedServer(Thread thread, DynamicRegistryManager.Impl impl, LevelStorage.Session session, SaveProperties saveProperties, ResourcePackManager resourcePackManager, Proxy proxy, DataFixer dataFixer, ServerResourceManager serverResourceManager, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, UserCache userCache, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory) { - super(thread, impl, session, saveProperties, resourcePackManager, proxy, dataFixer, serverResourceManager, minecraftSessionService, gameProfileRepository, userCache, worldGenerationProgressListenerFactory); - } - - @Inject(method = "setupServer", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/server/integrated/IntegratedServer;loadWorld()V", - shift = At.Shift.BEFORE), - cancellable = true - ) - public void setupServer(CallbackInfoReturnable info) throws IOException { - SandboxStorage.setClient((Client) client); - SandboxStorage.setServer((Server) this); - new SandboxLoader().load(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinItemGroup.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinItemGroup.java deleted file mode 100644 index 1445700..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinItemGroup.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.collection.DefaultedList; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ItemGroup.class) -public class MixinItemGroup { - - @Shadow - @Final - private int index; - - @Inject(method = "appendStacks", at = @At("RETURN")) - public void appendStacks(DefaultedList stacks, CallbackInfo info) { - boolean opOnly = MinecraftClient.getInstance().player.hasPermissionLevel(2); - if (this.index == ItemGroup.BUILDING_BLOCKS.getIndex()) { - stacks.add(new ItemStack(Items.BARRIER)); - } - if (this.index == ItemGroup.DECORATIONS.getIndex()) { - stacks.add(new ItemStack(Items.DRAGON_EGG)); - } - if (opOnly) { - if (this.index == ItemGroup.TRANSPORTATION.getIndex()) { - stacks.add(new ItemStack(Items.COMMAND_BLOCK_MINECART)); - } - if (this.index == ItemGroup.REDSTONE.getIndex()) { - stacks.add(new ItemStack(Items.COMMAND_BLOCK)); - } - if (this.index == ItemGroup.MISC.getIndex()) { - stacks.add(new ItemStack(Items.STRUCTURE_BLOCK)); - stacks.add(new ItemStack(Items.STRUCTURE_VOID)); - stacks.add(new ItemStack(Items.DEBUG_STICK)); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinKeyboard.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinKeyboard.java deleted file mode 100644 index 555263b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinKeyboard.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.Keyboard; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.Framebuffer; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.ScreenshotUtils; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import org.lwjgl.glfw.GLFW; -import org.sandboxpowered.sandbox.fabric.client.PanoramaHandler; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.File; -import java.util.function.Consumer; - -@Mixin(Keyboard.class) -public abstract class MixinKeyboard { - - @Shadow - @Final - private MinecraftClient client; - - @Shadow - protected abstract void debugWarn(String string, Object... objects); - - @Redirect(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/ScreenshotUtils;saveScreenshot(Ljava/io/File;IILnet/minecraft/client/gl/Framebuffer;Ljava/util/function/Consumer;)V")) - public void takeScreenshot(File file, int width, int height, Framebuffer framebuffer, Consumer consumer) { - if (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_P)) { - PanoramaHandler.INSTANCE.takeScreenshot(consumer); - } else { - ScreenshotUtils.saveScreenshot(file, width, height, framebuffer, consumer); - } - } - - @Inject(method = "processF3", at = @At("HEAD"), cancellable = true) - public void processF3(int button, CallbackInfoReturnable b) { - if (button == 81) { - this.debugWarn("debug.help.message"); - ChatHud chat = this.client.inGameHud.getChatHud(); - chat.addMessage(new TranslatableText("debug.reload_chunks.help")); - chat.addMessage(new TranslatableText("debug.show_hitboxes.help")); - chat.addMessage(new TranslatableText("debug.copy_location.help")); - chat.addMessage(new TranslatableText("debug.clear_chat.help")); - chat.addMessage(new TranslatableText("debug.cycle_renderdistance.help")); - chat.addMessage(new TranslatableText("debug.chunk_boundaries.help")); - chat.addMessage(new TranslatableText("debug.advanced_tooltips.help")); - chat.addMessage(new TranslatableText("debug.inspect.help")); - chat.addMessage(new TranslatableText("debug.creative_spectator.help")); - chat.addMessage(new TranslatableText("debug.pause_focus.help")); - chat.addMessage(new TranslatableText("debug.help.help")); - chat.addMessage(new TranslatableText("debug.reload_resourcepacks.help")); - chat.addMessage(new TranslatableText("debug.pause.help")); - chat.addMessage(new LiteralText("Test")); - b.setReturnValue(true); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinMinecraftClient.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinMinecraftClient.java deleted file mode 100644 index a489338..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinMinecraftClient.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.resource.ReloadableResourceManager; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceReloadMonitor; -import net.minecraft.util.Unit; -import org.sandboxpowered.internal.AddonSpec; -import org.sandboxpowered.sandbox.fabric.SandboxHooks; -import org.sandboxpowered.sandbox.fabric.client.AddonFolderResourcePack; -import org.sandboxpowered.sandbox.fabric.client.AddonResourcePack; -import org.sandboxpowered.sandbox.fabric.client.PanoramaHandler; -import org.sandboxpowered.sandbox.fabric.loader.SandboxLoader; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -@Mixin(MinecraftClient.class) -public abstract class MixinMinecraftClient { - - private void addonResourcePackModifications(List packs) { - if (SandboxLoader.loader != null && SandboxLoader.loader.getFabric() != null) - SandboxLoader.loader.getFabric().getAllAddons().forEach((addonInfo, addon) -> { - try { - AddonSpec spec = (AddonSpec) addonInfo; - Path path = Paths.get(spec.getPath().toURI()); - if (Files.isDirectory(path)) - packs.add(new AddonFolderResourcePack(path, spec)); - else - packs.add(new AddonResourcePack(path.toFile())); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - }); - } - -// TODO: Fix crash stuff -// -// @Redirect(method = "start", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;create(Ljava/lang/Throwable;Ljava/lang/String;)Lnet/minecraft/util/crash/CrashReport;")) -// private CrashReport create(Throwable throwable_1, String string) { -// Log.fatal(string, throwable_1); -// return CrashReport.create(throwable_1, string); -// } -// -// @Redirect(method = "start", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;fatal(Ljava/lang/String;Ljava/lang/Throwable;)V")) -// private void fatal(Logger logger, String message, Throwable t) { -// Log.fatal(message, t); -// } - - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;render(FJZ)V", shift = At.Shift.BEFORE)) - public void renderStart(CallbackInfo info) { - PanoramaHandler.INSTANCE.renderTick(true); - } - - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/toast/ToastManager;draw(Lnet/minecraft/client/util/math/MatrixStack;)V", shift = At.Shift.AFTER)) - public void renderEnd(CallbackInfo info) { - PanoramaHandler.INSTANCE.renderTick(false); - } - - @Inject(method = "close", at = @At("HEAD")) - public void shutdownGlobal(CallbackInfo info) { - SandboxHooks.close(); - } - - @Redirect(method = "reloadResources", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ReloadableResourceManager;beginMonitoredReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/resource/ResourceReloadMonitor;")) - public ResourceReloadMonitor reloadResources(ReloadableResourceManager manager, Executor var1, Executor var2, CompletableFuture var3, List packs) { - packs = new ArrayList<>(packs); - addonResourcePackModifications(packs); - return manager.beginMonitoredReload(var1, var2, var3, packs); - } - - @ModifyVariable(method = "openScreen", at = @At("HEAD"), ordinal = 0) - public Screen openScreen(Screen screen) { - return screen; - } - - /** - * @reason Sandbox Client Branding - * @author Coded - */ - @Overwrite - public String getVersionType() { - return "Sandbox"; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinResourcePackManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinResourcePackManager.java deleted file mode 100644 index 8a3a305..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinResourcePackManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.resource.ResourcePackManager; -import net.minecraft.resource.ResourcePackProfile; -import net.minecraft.resource.ResourcePackProvider; -import org.sandboxpowered.sandbox.fabric.resources.SandboxResourceCreator; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.HashSet; -import java.util.Set; - -@Mixin(ResourcePackManager.class) -public class MixinResourcePackManager { - @Shadow - @Final - @Mutable - private Set providers; - - @Inject(method = "(Lnet/minecraft/resource/ResourcePackProfile$Factory;[Lnet/minecraft/resource/ResourcePackProvider;)V", at = @At("RETURN")) - public void construct(ResourcePackProfile.Factory factory, ResourcePackProvider[] resourcePackProviders, CallbackInfo ci) { - providers = new HashSet<>(providers); - providers.add(new SandboxResourceCreator()); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinScreen.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinScreen.java deleted file mode 100644 index 728cc39..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinScreen.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.AbstractButtonWidget; -import org.sandboxpowered.sandbox.fabric.internal.ISandboxScreen; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.List; - -@Mixin(Screen.class) -public abstract class MixinScreen implements ISandboxScreen { - @Shadow - @Final - protected List buttons; - - @Shadow - protected abstract T addButton(T button); - - @Override - public List getButtons() { - return buttons; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinTitleScreen.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinTitleScreen.java deleted file mode 100644 index 10c6949..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinTitleScreen.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.gui.CubeMapRenderer; -import net.minecraft.client.gui.RotatingCubeMapRenderer; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.texture.TextureManager; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Arrays; -import java.util.Random; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -@Mixin(TitleScreen.class) -public abstract class MixinTitleScreen { - private static final CubeMapRenderer[] PANORAMA_CUBE_MAPS = new CubeMapRenderer[5]; - @Shadow - @Final - public static CubeMapRenderer PANORAMA_CUBE_MAP; - @Shadow - @Final - private static Identifier MINECRAFT_TITLE_TEXTURE; - @Shadow - @Final - private static Identifier EDITION_TITLE_TEXTURE; - @Shadow - @Final - private static Identifier PANORAMA_OVERLAY; - - static { - for (int i = 0; i < 5; i++) { - PANORAMA_CUBE_MAPS[i] = new CubeMapRenderer(new Identifier("textures/gui/title/background/panorama_" + i + "/panorama")); - } - } - - private final Random random = new Random(); - @Mutable - @Shadow - @Final - private RotatingCubeMapRenderer backgroundRenderer; - - @Inject(method = "loadTexturesAsync", at = @At("HEAD"), cancellable = true) - private static void loadTextures(TextureManager textureManager, Executor executor, CallbackInfoReturnable> info) { - info.setReturnValue(CompletableFuture.allOf( - textureManager.loadTextureAsync(MINECRAFT_TITLE_TEXTURE, executor), - textureManager.loadTextureAsync(EDITION_TITLE_TEXTURE, executor), - textureManager.loadTextureAsync(PANORAMA_OVERLAY, executor), - PANORAMA_CUBE_MAP.loadTexturesAsync(textureManager, executor), - CompletableFuture.allOf(Arrays.stream(PANORAMA_CUBE_MAPS).map(cube -> cube.loadTexturesAsync(textureManager, executor)).toArray(CompletableFuture[]::new)) - )); - } - - @Inject(method = "(Z)V", at = @At("RETURN")) - public void constructor(boolean bl, CallbackInfo info) { - this.backgroundRenderer = new RotatingCubeMapRenderer(PANORAMA_CUBE_MAPS[random.nextInt(PANORAMA_CUBE_MAPS.length)]); - } - -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinVideoOptionsScreen.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinVideoOptionsScreen.java deleted file mode 100644 index d2953af..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/client/MixinVideoOptionsScreen.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.client; - -import net.minecraft.client.gui.screen.VideoOptionsScreen; -import net.minecraft.client.gui.widget.ButtonListWidget; -import net.minecraft.client.options.Option; -import org.apache.commons.lang3.ArrayUtils; -import org.sandboxpowered.sandbox.fabric.SandboxOptions; -import org.sandboxpowered.sandbox.fabric.internal.ISandboxScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(VideoOptionsScreen.class) -public abstract class MixinVideoOptionsScreen implements ISandboxScreen { - @Redirect(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonListWidget;addAll([Lnet/minecraft/client/options/Option;)V")) - public void addAll(ButtonListWidget widget, Option[] options) { - widget.addAll(ArrayUtils.addAll(options, SandboxOptions.CULL_PARTICLES, SandboxOptions.WORLD_BORDER)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/crash/MixinCrashReport.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/crash/MixinCrashReport.java deleted file mode 100644 index a71218d..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/crash/MixinCrashReport.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.crash; - -import net.minecraft.util.crash.CrashReport; -import net.minecraft.util.crash.CrashReportSection; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(CrashReport.class) -public abstract class MixinCrashReport { - - @Shadow - public abstract CrashReportSection getSystemDetailsSection(); - - @Inject(at = @At("RETURN"), method = "fillSystemDetails") - private void fillSystemDetails(CallbackInfo info) { - getSystemDetailsSection().add("Sandbox Addons", () -> { - StringBuilder builder = new StringBuilder(); -// if (SandboxServer.INSTANCE != null) { -// builder.append("Server: \n"); -// SandboxServer.INSTANCE.loader.getAddons().forEach(spec -> { -// builder.append("- ").append(spec.getId()); -// -// if (!spec.getTitle().equals(spec.getId())) { -// builder.append(" \"").append(spec.getTitle()).append("\""); -// } -// -// builder.append(" @ ").append(spec.getVersion().toString()).append("\n"); -// }); -// } -// -// if (SandboxClient.INSTANCE != null) { -// builder.append("Client: \n"); -// SandboxClient.INSTANCE.loader.getAddons().forEach(spec -> { -// builder.append("- ").append(spec.getId()); -// -// if (!spec.getTitle().equals(spec.getId())) { -// builder.append(" \"").append(spec.getTitle()).append("\""); -// } -// -// builder.append(" @ ").append(spec.getVersion().toString()).append("\n"); -// }); -// } - - return builder.toString(); - }); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantment.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantment.java deleted file mode 100644 index b770a62..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantment.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.enchant; - -import net.minecraft.enchantment.Enchantment; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.util.NumberUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(Enchantment.class) -public class MixinEnchantment { - @Redirect(method = "getName(I)Lnet/minecraft/text/Text;", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/MutableText;append(Lnet/minecraft/text/Text;)Lnet/minecraft/text/MutableText;")) - private MutableText text(MutableText text, Text value, int i) { - return text.append(SandboxConfig.enchantmentDecimal.getBoolean() ? String.valueOf(i) : NumberUtil.toRoman(i)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantmentHelper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantmentHelper.java deleted file mode 100644 index d2e169f..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/enchant/MixinEnchantmentHelper.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.enchant; - -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.EnchantmentLevelEntry; -import net.minecraft.enchantment.EnchantmentTarget; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.Iterator; -import java.util.List; - -@Mixin(EnchantmentHelper.class) -public abstract class MixinEnchantmentHelper { - - private static final ThreadLocal ENCHANTMENT_THREAD_LOCAL = new ThreadLocal<>(); - - @Inject(method = "getPossibleEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/Enchantment;isTreasure()Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private static void localEnchantment(int power, ItemStack stack, boolean allowTreasure, CallbackInfoReturnable info, List ret, Item item, boolean isBook, Iterator itr, Enchantment enchantment) { - ENCHANTMENT_THREAD_LOCAL.set(enchantment); - } - - @Redirect(method = "getPossibleEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/EnchantmentTarget;isAcceptableItem(Lnet/minecraft/item/Item;)Z")) - private static boolean isAcceptableItem(EnchantmentTarget target, Item item, int i, ItemStack itemStack, boolean bl) { - Enchantment enchantment = ENCHANTMENT_THREAD_LOCAL.get(); - ENCHANTMENT_THREAD_LOCAL.remove(); - if (enchantment == null) { - return target.isAcceptableItem(item); - } - return enchantment.isAcceptableItem(itemStack); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientConnection.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientConnection.java deleted file mode 100644 index aa5b5be..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientConnection.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import com.mojang.authlib.properties.Property; -import net.minecraft.network.ClientConnection; -import org.sandboxpowered.sandbox.fabric.internal.ClientConnectionInternal; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.net.SocketAddress; -import java.util.UUID; - -@Mixin(ClientConnection.class) -public class MixinClientConnection implements ClientConnectionInternal { - @Shadow - private SocketAddress address; - private UUID sandboxUUID; - private Property[] sandboxProfile; - - @Override - public void setSocketAddress(SocketAddress address) { - this.address = address; - } - - @Override - public UUID getSandboxUUID() { - return sandboxUUID; - } - - @Override - public void setSandboxUUID(UUID uuid) { - this.sandboxUUID = uuid; - } - - @Override - public Property[] getSandboxProfile() { - return sandboxProfile; - } - - @Override - public void setSandboxProfile(Property[] profile) { - this.sandboxProfile = profile; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientPlayNetworkHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientPlayNetworkHandler.java deleted file mode 100644 index 73f46e0..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinClientPlayNetworkHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.sandboxpowered.sandbox.fabric.network.NetworkManager; -import org.sandboxpowered.sandbox.fabric.network.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientPlayNetworkHandler.class) -public class MixinClientPlayNetworkHandler { - - @Inject(method = "onCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER, remap = false), cancellable = true) - public void onCustomPayload(CustomPayloadS2CPacket s2c, CallbackInfo info) { - CustomPayloadPacket customPayloadPacket = (CustomPayloadPacket) s2c; - PacketByteBuf data = null; - try { - Identifier channel = customPayloadPacket.channel(); - if (!channel.getNamespace().equals("minecraft")) { //Override non-vanilla packets - Class packetClass = NetworkManager.get(channel); - if (packetClass != null) { - data = customPayloadPacket.data(); - Packet packet = packetClass.getConstructor().newInstance(); - packet.read(data); - packet.apply(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (data != null) { - data.release(); - info.cancel(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadC2SPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadC2SPacket.java deleted file mode 100644 index e16d749..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadC2SPacket.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(CustomPayloadC2SPacket.class) -public class MixinCustomPayloadC2SPacket implements CustomPayloadPacket { - @Shadow - private Identifier channel; - - @Shadow - private PacketByteBuf data; - - @Override - public Identifier channel() { - return this.channel; - } - - @Override - public PacketByteBuf data() { - return this.data; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadS2CPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadS2CPacket.java deleted file mode 100644 index deee568..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinCustomPayloadS2CPacket.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(CustomPayloadS2CPacket.class) -public class MixinCustomPayloadS2CPacket implements CustomPayloadPacket { - @Shadow - private Identifier channel; - - @Shadow - private PacketByteBuf data; - - @Override - public Identifier channel() { - return this.channel; - } - - @Override - public PacketByteBuf data() { - return this.data; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryRequestS2CPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryRequestS2CPacket.java deleted file mode 100644 index 147badb..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryRequestS2CPacket.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.internal.LoginQueryRequestPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(LoginQueryRequestS2CPacket.class) -public class MixinLoginQueryRequestS2CPacket implements LoginQueryRequestPacket { - @Shadow - private int queryId; - - @Shadow - private Identifier channel; - - @Shadow - private PacketByteBuf payload; - - @Override - public void setQueryId(int queryId) { - this.queryId = queryId; - } - - @Override - public void setChannel(Identifier channel) { - this.channel = channel; - } - - @Override - public void setPayload(PacketByteBuf payload) { - this.payload = payload; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryResponseC2SPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryResponseC2SPacket.java deleted file mode 100644 index 6a596ef..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinLoginQueryResponseC2SPacket.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(LoginQueryResponseC2SPacket.class) -public class MixinLoginQueryResponseC2SPacket implements CustomPayloadPacket.LoginQueryPacket { - @Shadow - private int queryId; - - @Shadow - private PacketByteBuf response; - - @Override - public int getQueryId() { - return this.queryId; - } - - @Override - public PacketByteBuf getBuffer() { - return this.response; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinPlayerManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinPlayerManager.java deleted file mode 100644 index 49abd7d..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinPlayerManager.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.ClientConnection; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(PlayerManager.class) -public class MixinPlayerManager { - - @Inject(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendWorldInfo(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/server/world/ServerWorld;)V"), cancellable = true) - public void tick(ClientConnection connection, ServerPlayerEntity entity, CallbackInfo info) { -// NetworkManager.sendTo(SandboxServer.INSTANCE.createAddonSyncPacket(), entity); todo - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerConfigHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerConfigHandler.java deleted file mode 100644 index dd22bd7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerConfigHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.ServerConfigHandler; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ServerConfigHandler.class) -public class MixinServerConfigHandler { - @Redirect(method = "lookupProfile", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;isOnlineMode()Z")) - private static boolean lookupProfile(MinecraftServer minecraftServer) { - return SandboxConfig.forwarding.getEnum(SandboxConfig.ServerForwarding.class).isForwarding() || minecraftServer.isOnlineMode(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerLoginNetworkHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerLoginNetworkHandler.java deleted file mode 100644 index c9ba39c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerLoginNetworkHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import com.mojang.authlib.GameProfile; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; -import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; -import net.minecraft.server.network.ServerLoginNetworkHandler; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.internal.ClientConnectionInternal; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.sandboxpowered.sandbox.fabric.util.VelocityUtil; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.net.InetSocketAddress; -import java.util.concurrent.ThreadLocalRandom; - -@Mixin(ServerLoginNetworkHandler.class) -public abstract class MixinServerLoginNetworkHandler { - - @Shadow - @Final - public ClientConnection connection; - @Shadow - private GameProfile profile; - private int velocityId = -1; - private boolean velocityConn = false; - - @Shadow - public abstract void disconnect(Text text); - - @Shadow - public abstract void acceptPlayer(); - - @Inject(method = "onHello", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler$State;READY_TO_ACCEPT:Lnet/minecraft/server/network/ServerLoginNetworkHandler$State;"), cancellable = true) - public void onHello(CallbackInfo info) { - if (SandboxConfig.forwarding.getEnum(SandboxConfig.ServerForwarding.class) == SandboxConfig.ServerForwarding.VELOCITY) { - this.velocityId = ThreadLocalRandom.current().nextInt(); - velocityConn = false; - LoginQueryRequestS2CPacket packet = VelocityUtil.create(velocityId); - this.connection.send(packet); - - info.cancel(); - } - } - - @Inject(method = "acceptPlayer", at = @At("HEAD"), cancellable = true) - public void acceptPlayer(CallbackInfo info) { - if (SandboxConfig.forwarding.getEnum(SandboxConfig.ServerForwarding.class) == SandboxConfig.ServerForwarding.VELOCITY && !velocityConn) { - this.disconnect(new LiteralText("This server requires you to log in through velocity")); - info.cancel(); - } - } - - @Inject(method = "onQueryResponse", at = @At("HEAD"), cancellable = true) - public void onQueryResponse(LoginQueryResponseC2SPacket packet, CallbackInfo info) { - if (SandboxConfig.forwarding.getEnum(SandboxConfig.ServerForwarding.class) == SandboxConfig.ServerForwarding.VELOCITY && velocityId == ((CustomPayloadPacket.LoginQueryPacket) packet).getQueryId()) { - PacketByteBuf buf = ((CustomPayloadPacket.LoginQueryPacket) packet).getBuffer(); - if (buf == null) { - this.disconnect(new LiteralText("This server requires you to log in through velocity")); - info.cancel(); - return; - } - if (!VelocityUtil.checkIntegrity(buf)) { - this.disconnect(new LiteralText("Unable to verify player details")); - info.cancel(); - return; - } - - ((ClientConnectionInternal) this.connection).setSocketAddress(new InetSocketAddress(VelocityUtil.readAddress(buf), ((InetSocketAddress) this.connection.getAddress()).getPort())); - this.profile = VelocityUtil.createProfile(buf); - velocityConn = true; - acceptPlayer(); - info.cancel(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerPlayNetworkHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerPlayNetworkHandler.java deleted file mode 100644 index 5ca7cbe..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/networking/MixinServerPlayNetworkHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.networking; - -import net.minecraft.network.NetworkThreadUtils; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.internal.CustomPayloadPacket; -import org.sandboxpowered.sandbox.fabric.network.NetworkManager; -import org.sandboxpowered.sandbox.fabric.network.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ServerPlayNetworkHandler.class) -public class MixinServerPlayNetworkHandler { - - @Shadow - public ServerPlayerEntity player; - - @Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true) - public void onCustomPayload(CustomPayloadC2SPacket c2s, CallbackInfo info) { - NetworkThreadUtils.forceMainThread(c2s, (ServerPlayNetworkHandler) (Object) this, this.player.getServerWorld()); - CustomPayloadPacket customPayloadPacket = (CustomPayloadPacket) c2s; - PacketByteBuf data = null; - try { - Identifier channel = customPayloadPacket.channel(); - if (!channel.getNamespace().equals("minecraft")) { //Override non-vanilla packets - Class packetClass = NetworkManager.get(channel); - if (packetClass != null) { - data = customPayloadPacket.data(); - Packet packet = packetClass.getConstructor().newInstance(); - packet.read(data); - packet.apply(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (data != null) { - data.release(); - info.cancel(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinRegistry.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinRegistry.java deleted file mode 100644 index df6a798..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinRegistry.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.registry; - -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(Registry.class) -public abstract class MixinRegistry implements SandboxInternal.RegistryKeyObtainer { - @Shadow - @Final - private RegistryKey> registryKey; - - @Override - public RegistryKey> sandboxGetRegistryKey() { - return registryKey; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinSimpleRegistry.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinSimpleRegistry.java deleted file mode 100644 index 00d36a6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/registry/MixinSimpleRegistry.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.registry; - -import com.google.common.collect.BiMap; -import com.mojang.serialization.Lifecycle; -import it.unimi.dsi.fastutil.objects.ObjectList; -import net.minecraft.util.Identifier; -import net.minecraft.util.collection.Int2ObjectBiMap; -import net.minecraft.util.registry.MutableRegistry; -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.util.registry.SimpleRegistry; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.content.Content; -import org.sandboxpowered.sandbox.fabric.impl.WrappedRegistry; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.Log; -import org.sandboxpowered.sandbox.fabric.util.RegistryUtil; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.HashSet; -import java.util.Set; - -@Mixin(SimpleRegistry.class) -public abstract class MixinSimpleRegistry> extends MutableRegistry implements SandboxInternal.Registry { - private final Set> keys = new HashSet<>(); - - @Shadow - protected Object[] randomEntries; - protected Int2ObjectBiMap storedIndex = new Int2ObjectBiMap<>(256); - @Shadow - private int nextId; - private int vanillaNext; - private boolean hasStored; - private WrappedRegistry sboxRegistry; - @Shadow - @Final - private ObjectList rawIdToEntry; - @Shadow - @Final - private BiMap idToEntry; - @Shadow - @Final - private BiMap, T> keyToEntry; - - protected MixinSimpleRegistry(RegistryKey> registryKey, Lifecycle lifecycle) { - super(registryKey, lifecycle); - } - - @Shadow - @Nullable - public abstract T get(Identifier id); - - @Override - public void sandboxStore() { - vanillaNext = nextId; - storedIndex.clear(); - for (int i = 0; i < vanillaNext; i++) { - storedIndex.put(this.rawIdToEntry.get(i), i); - } - randomEntries = null; - keys.clear(); - hasStored = true; - Log.debug("Stored " + vanillaNext + " objects in " + getKey().getValue()); - } - - - @Inject(method = "set(ILnet/minecraft/util/registry/RegistryKey;Ljava/lang/Object;Lcom/mojang/serialization/Lifecycle;Z)Ljava/lang/Object;", at = @At(value = "RETURN")) - public void set(int i, RegistryKey registryKey, V object, Lifecycle lifecycle, boolean bl, CallbackInfoReturnable cir) { - if (hasStored) { - keys.add(registryKey); - RegistryUtil.doOnSet(object); - } - } - - @Override - public void sandboxSet(WrappedRegistry registry) { - this.sboxRegistry = registry; - } - - @Override - public WrappedRegistry sandboxGet() { - return this.sboxRegistry; - } - - @Override - public void sandboxReset() { - if (nextId != vanillaNext) { - Log.debug("Resetting " + (nextId - vanillaNext) + " objects in " + getKey().getValue()); - sboxRegistry.clearCache(); - nextId = vanillaNext; - this.rawIdToEntry.clear(); - this.rawIdToEntry.size(vanillaNext); - for (int i = 0; i < vanillaNext; i++) { - this.rawIdToEntry.set(i, storedIndex.get(i)); - } - randomEntries = null; - keys.forEach(id -> { - idToEntry.remove(id.getValue()); - keyToEntry.remove(id); - }); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinDedicatedServer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinDedicatedServer.java deleted file mode 100644 index 70d7ac4..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinDedicatedServer.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.server; - -import net.minecraft.server.dedicated.MinecraftDedicatedServer; -import org.sandboxpowered.api.server.Server; -import org.sandboxpowered.sandbox.fabric.loader.SandboxLoader; -import org.sandboxpowered.sandbox.fabric.util.SandboxStorage; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.IOException; - -@Mixin(value = MinecraftDedicatedServer.class) -public abstract class MixinDedicatedServer extends MixinMinecraftServer { - @Inject(method = "setupServer", - at = @At(value = "INVOKE", - target = "net/minecraft/server/dedicated/MinecraftDedicatedServer.setPlayerManager(Lnet/minecraft/server/PlayerManager;)V", - shift = At.Shift.AFTER), - cancellable = true - ) - public void setupServer(CallbackInfoReturnable info) throws IOException { - SandboxStorage.setServer((Server) this); - new SandboxLoader().load(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinMinecraftServer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinMinecraftServer.java deleted file mode 100644 index 9dfb989..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/server/MixinMinecraftServer.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.server; - -import net.minecraft.server.MinecraftServer; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.SandboxHooks; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(MinecraftServer.class) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinMinecraftServer { - - @Shadow - public abstract boolean isDedicated(); - - @Inject(method = "isOnlineMode", at = @At("HEAD"), cancellable = true) - public void isOnlineMode(CallbackInfoReturnable info) { - if (this.isDedicated() && SandboxConfig.forwarding.getEnum(SandboxConfig.ServerForwarding.class).isForwarding()) - info.setReturnValue(false); - } - - @Inject(method = "shutdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ServerResourceManager;close()V"), cancellable = true) - public void shutdown(CallbackInfo info) { - SandboxHooks.shutdown(); - } - - /** - * @author B0undarybreaker - */ - @ModifyConstant(method = "getServerModName") - public String getServerModName(String original) { - return "Sandbox"; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/world/MixinServerWorld.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/world/MixinServerWorld.java deleted file mode 100644 index 753fd9a..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/fabric/world/MixinServerWorld.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.fabric.world; - -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Mixin(ServerWorld.class) -public abstract class MixinServerWorld { - @Redirect(method = "updateSleepingPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSpectator()Z")) - public boolean isSpectator(ServerPlayerEntity entity) { - return entity.isSpectator() || WrappingUtil.convert(entity).isSleepingIgnored(); - } - - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;noneMatch(Ljava/util/function/Predicate;)Z")) - public boolean noneMatch(Stream stream, Predicate predicate) { - return stream.noneMatch(predicate.and(entity -> !WrappingUtil.convert(entity).isSleepingIgnored())); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinAbstractBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinAbstractBlock.java deleted file mode 100644 index eb41ec8..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinAbstractBlock.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.AbstractBlock; -import org.sandboxpowered.api.block.Block; -import org.spongepowered.asm.mixin.*; - -@Mixin(AbstractBlock.class) -@Implements(@Interface(iface = Block.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinAbstractBlock { - @Shadow - public abstract boolean hasBlockEntity(); - - @Intrinsic - public boolean sbx$hasBlockEntity() { - return this.hasBlockEntity(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlock.java deleted file mode 100644 index d7959af..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlock.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.AbstractBlock.Settings; -import net.minecraft.block.BlockEntityProvider; -import net.minecraft.block.InventoryProvider; -import net.minecraft.block.Waterloggable; -import net.minecraft.entity.LivingEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.state.StateManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.WorldAccess; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.block.FluidLoggable; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.component.Component; -import org.sandboxpowered.api.component.Components; -import org.sandboxpowered.api.component.fluid.FluidLoggingContainer; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.item.Items; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.Mono; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Vec3f; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.BlockWrapper; -import org.sandboxpowered.sandbox.fabric.util.wrapper.SidedRespective; -import org.sandboxpowered.sandbox.fabric.util.wrapper.StateFactoryImpl; -import org.sandboxpowered.sandbox.fabric.util.wrapper.V2SInventory; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Optional; - -@Mixin(net.minecraft.block.Block.class) -@Implements(@Interface(iface = Block.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings("java:S100") -public abstract class MixinBlock extends AbstractBlock implements SandboxInternal.StateFactoryHolder { - @Shadow - @Final - protected StateManager stateManager; - private StateFactory sandboxFactory; - private Block.Settings sbxSettings; - - public MixinBlock(Settings settings) { - super(settings); - } - - @Shadow - public abstract net.minecraft.block.BlockState getDefaultState(); - - @Shadow - public abstract void onPlaced(net.minecraft.world.World world, BlockPos blockPos, net.minecraft.block.BlockState blockState, @Nullable LivingEntity livingEntity, net.minecraft.item.ItemStack itemStack); - - @Shadow - public abstract void onBroken(WorldAccess iWorld, BlockPos blockPos, net.minecraft.block.BlockState blockState); - - @SuppressWarnings("unchecked") - @Inject(method = "", at = @At("RETURN")) - public void constructor(Settings settings, CallbackInfo info) { - if (!((Object) this instanceof BlockWrapper)) { - sandboxFactory = new StateFactoryImpl<>(this.stateManager, b -> (Block) b, s -> (BlockState) s); - ((SandboxInternal.StateFactory) this.stateManager).setSboxFactory(sandboxFactory); - } - } - - public Block.Settings sbx$getSettings() { - if (sbxSettings == null) { - sbxSettings = Block.Settings.builder(WrappingUtil.convert(material)) - .setHardness(0) - .setLuminance(0) - .setResistance(resistance) - .setSlipperiness(slipperiness) - .setJumpVelocity(jumpVelocityMultiplier) - .setVelocity(velocityMultiplier) - .build(); - } - return sbxSettings; - } - - @Override - public StateFactory getSandboxStateFactory() { - return sandboxFactory; - } - - public boolean sbx$isAir(BlockState state) { - return state.isAir(); - } - - public BlockState sbx$getBaseState() { - return (BlockState) this.getDefaultState(); - } - - public InteractionResult sbx$onBlockUsed(World world, Position pos, BlockState state, PlayerEntity player, Hand hand, Direction side, Vec3f hit) { -// onUse(WrappingUtil.convert(state), WrappingUtil.convert(world), WrappingUtil.convert(pos), WrappingUtil.convert(player), WrappingUtil.convert(hand), null); - return InteractionResult.IGNORE; - } - - public void sbx$onBlockClicked(World world, Position pos, BlockState state, PlayerEntity player) { - onBlockBreakStart(WrappingUtil.convert(state), WrappingUtil.convert(world), WrappingUtil.convert(pos), WrappingUtil.convert(player)); - } - - public Optional sbx$asItem() { - Item item = (Item) asItem(); - if (Items.AIR.matches(item)) - return Optional.empty(); - return Optional.of(item); - } - - public void sbx$onBlockPlaced(World world, Position position, BlockState state, Entity entity, ItemStack itemStack) { - this.onPlaced( - WrappingUtil.convert(world), - WrappingUtil.convert(position), - WrappingUtil.convert(state), - WrappingUtil.convertToLivingOrNull(entity), - WrappingUtil.convert(itemStack) - ); - } - - public void sbx$onBlockBroken(World world, Position position, BlockState state) { - this.onBroken(WrappingUtil.convert(world), WrappingUtil.convert(position), WrappingUtil.convert(state)); - } - - public Mono sbx$getComponent(WorldReader reader, Position position, BlockState state, Component component, @Nullable Direction side) { - if (component == Components.INVENTORY_COMPONENT) { - if (this instanceof InventoryProvider) { - SidedInventory inventory = ((InventoryProvider) this).getInventory((net.minecraft.block.BlockState) state, (WorldAccess) reader, (BlockPos) position); - if (side != null) - return Mono.of(new SidedRespective(inventory, side)).cast(); - return Mono.of(new V2SInventory(inventory)).cast(); - } - net.minecraft.block.entity.BlockEntity entity = ((BlockView) reader).getBlockEntity((BlockPos) position); - if (entity instanceof Inventory) { - if (side != null && entity instanceof SidedInventory) - return Mono.of(new SidedRespective((SidedInventory) entity, side)).cast(); - return Mono.of(new V2SInventory((Inventory) entity)).cast(); - } - } - if (component == Components.FLUID_COMPONENT && this instanceof Waterloggable) { - FluidLoggingContainer container = new FluidLoggingContainer((FluidLoggable) this, reader, position, state, side); - return Mono.of(container).cast(); - } - return Mono.empty(); - } - - @Nullable - public BlockEntity sbx$createBlockEntity(WorldReader reader) { - if (hasBlockEntity()) - return (BlockEntity) ((BlockEntityProvider) this).createBlockEntity(WrappingUtil.convert(reader)); - return null; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockClient.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockClient.java deleted file mode 100644 index 96184a7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.block.Block.class) -@Implements(@Interface(iface = Block.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100", "java:S1610"}) -public abstract class MixinBlockClient { - @Shadow - public abstract net.minecraft.item.ItemStack getPickStack(BlockView world, BlockPos pos, net.minecraft.block.BlockState state); - - public ItemStack sbx$getPickStack(WorldReader reader, Position position, BlockState state) { - return WrappingUtil.cast(getPickStack( - (BlockView) reader, - (BlockPos) position, - (net.minecraft.block.BlockState) state - ), ItemStack.class); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockEntity.java deleted file mode 100644 index 2ba2298..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinBlockEntity.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.block.entity.BlockEntity.class) -@Implements(@Interface(iface = BlockEntity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinBlockEntity { - @Shadow - public abstract BlockPos getPos(); - - @Shadow - public abstract BlockEntityType getType(); - - @Shadow - @Nullable - public abstract net.minecraft.world.World getWorld(); - - public World sbx$getWorld() { - return (World) this.getWorld(); - } - - public Position sbx$getPosition() { - return (Position) this.getPos(); - } - - public BlockEntity.Type sbx$getType() { - return (BlockEntity.Type) this.getType(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinHopperBlockEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinHopperBlockEntity.java deleted file mode 100644 index 9562818..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinHopperBlockEntity.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.HopperBlock; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.Hopper; -import org.sandboxpowered.api.component.Components; -import org.sandboxpowered.api.component.Inventory; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.Mono; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(net.minecraft.block.entity.HopperBlockEntity.class) -public abstract class MixinHopperBlockEntity extends BlockEntity { - public MixinHopperBlockEntity(BlockEntityType type) { - super(type); - } - - @Inject(method = "extract(Lnet/minecraft/block/entity/Hopper;)Z", at = @At("HEAD"), cancellable = true) - private static void extract(Hopper hopper, CallbackInfoReturnable info) { - World world = (World) hopper.getWorld(); - if (world == null) { - info.setReturnValue(false); - return; - } - Position position = Position.create((int) Math.floor(hopper.getHopperX()), (int) Math.floor(hopper.getHopperY()), (int) Math.floor(hopper.getHopperZ())); - Position abovePos = position.up(); - BlockState aboveState = world.getBlockState(abovePos); - Mono mono = aboveState.getComponent(world, abovePos, Components.INVENTORY_COMPONENT, Direction.DOWN); - if (mono.isPresent()) { - Inventory inventory = mono.get(); - if (inventory.isEmpty()) { - info.setReturnValue(false); - return; - } - - for (int slot : inventory) { - ItemStack stack = inventory.extract(slot, 1, true); - if (!stack.isEmpty()) { - for (int hopperSlot = 0; hopperSlot < hopper.size(); hopperSlot++) { - if (hopper.isValid(hopperSlot, WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class))) { - stack = inventory.extract(slot, 1); - net.minecraft.item.ItemStack hopperStack = hopper.getStack(hopperSlot); - if (hopperStack.isEmpty()) { - hopper.setStack(hopperSlot, WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class)); - info.setReturnValue(true); - return; - } else if (hopper.getMaxCountPerStack() >= hopperStack.getCount() + stack.getCount()) { - net.minecraft.item.ItemStack copy = hopperStack.copy(); - copy.increment(stack.getCount()); - hopper.setStack(hopperSlot, copy); - info.setReturnValue(true); - return; - } - } - } - } - } - } - info.setReturnValue(false); - } - - @Inject(method = "insert", at = @At("HEAD"), cancellable = true) - public void insert(CallbackInfoReturnable info) { - World world = (World) this.getWorld(); - Position position = (Position) getPos(); - if (world == null) { - info.setReturnValue(false); - return; - } - BlockState state = (BlockState) getCachedState(); - Direction direction = WrappingUtil.convert(getCachedState().get(HopperBlock.FACING)); - Inventory hopperInventory = state.getComponent(world, position, Components.INVENTORY_COMPONENT).orElse(null); - if (hopperInventory != null) { - Position offset = position.offset(direction); - BlockState other = world.getBlockState(offset); - Mono mono = other.getComponent(world, offset, Components.INVENTORY_COMPONENT, direction.getOppositeDirection()); - if (mono.isPresent()) { - Inventory inputInv = mono.get(); - for (int slot : hopperInventory) { - ItemStack input = hopperInventory.extract(slot, 1, true); - if (!input.isEmpty() && inputInv.insert(input, true).isEmpty()) { - inputInv.insert(hopperInventory.extract(slot, 1)); - info.setReturnValue(true); - return; - } - } - info.setReturnValue(false); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinMaterial.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinMaterial.java deleted file mode 100644 index fa90ae9..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinMaterial.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.piston.PistonBehavior; -import org.sandboxpowered.api.block.Material; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.block.Material.class) -@Implements(@Interface(iface = Material.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinMaterial { - - @Shadow - public abstract PistonBehavior getPistonBehavior(); - - @Shadow - public abstract boolean blocksMovement(); - - @Shadow - public abstract boolean isBurnable(); - - @Shadow - public abstract boolean isLiquid(); - - @Shadow - public abstract boolean blocksLight(); - - @Shadow - public abstract boolean isReplaceable(); - - @Shadow - public abstract boolean isSolid(); - - public Material.PistonInteraction sbx$getPistonInteraction() { - return WrappingUtil.convert(getPistonBehavior()); - } - - public boolean sbx$doesBlockMovement() { - return blocksMovement(); - } - - public boolean sbx$isBurnable() { - return isBurnable(); - } - - public boolean sbx$isBreakByHand() { - return sbx$isBreakByHand(); - } - - public boolean sbx$isLiquid() { - return isLiquid(); - } - - public boolean sbx$doesBlockLight() { - return blocksLight(); - } - - public boolean sbx$isReplaceable() { - return isReplaceable(); - } - - public boolean sbx$isSolid() { - return isSolid(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinSandboxBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinSandboxBlock.java deleted file mode 100644 index 05f3d52..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinSandboxBlock.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import org.sandboxpowered.api.block.BaseBlock; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(value = BaseBlock.class, remap = false) -@Unique -public abstract class MixinSandboxBlock implements SandboxInternal.WrappedInjection { - private SandboxInternal.IBlockWrapper sandboxWrappedInjection; - - @Override - public final SandboxInternal.IBlockWrapper getInjectionWrapped() { - return sandboxWrappedInjection; - } - - @Override - public final void setInjectionWrapped(SandboxInternal.IBlockWrapper o) { - sandboxWrappedInjection = o; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinWaterlogged.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinWaterlogged.java deleted file mode 100644 index 2ad5141..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/MixinWaterlogged.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block; - -import net.minecraft.block.Waterloggable; -import org.sandboxpowered.api.block.FluidLoggable; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Waterloggable.class) -public interface MixinWaterlogged extends FluidLoggable { - @Override - default boolean needsWaterloggedProperty() { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/entity/MixinBlockEntityType.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/entity/MixinBlockEntityType.java deleted file mode 100644 index 381128b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/block/entity/MixinBlockEntityType.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.block.entity; - -import net.minecraft.block.entity.BlockEntityType; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(BlockEntityType.class) -@Implements(@Interface(iface = BlockEntity.Type.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public class MixinBlockEntityType { -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinFluidRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinFluidRenderer.java deleted file mode 100644 index d20053c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinFluidRenderer.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.block.FluidRenderer; -import net.minecraft.client.texture.Sprite; -import net.minecraft.client.texture.SpriteAtlasTexture; -import net.minecraft.fluid.FluidState; -import net.minecraft.screen.PlayerScreenHandler; -import net.minecraft.tag.FluidTags; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.BlockRenderView; -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.FluidWrapper; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Objects; - -@Mixin(FluidRenderer.class) -public abstract class MixinFluidRenderer { - - private final Map spriteMap = new LinkedHashMap<>(); - private final ThreadLocal stateThreadLocal = new ThreadLocal<>(); - @Shadow - @Final - private Sprite[] waterSprites; - - @Inject(at = @At("RETURN"), method = "onResourceReload") - public void reload(CallbackInfo info) { - SpriteAtlasTexture texture = Objects.requireNonNull((SpriteAtlasTexture) MinecraftClient.getInstance().getTextureManager().getTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE)); - spriteMap.clear(); - Registry.FLUID.forEach(fluid -> { - if (fluid instanceof FluidWrapper) { - Sprite[] sprites = new Sprite[2]; - sprites[0] = texture.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).getFluid().getTexturePath(false))); - sprites[1] = texture.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).getFluid().getTexturePath(true))); - spriteMap.put(((FluidWrapper) fluid).getFluid(), sprites); - } - }); - } - - @Inject(at = @At("HEAD"), method = "render", cancellable = true) - public void draw(BlockRenderView view, BlockPos pos, VertexConsumer bufferBuilder, FluidState state, CallbackInfoReturnable info) { - stateThreadLocal.set(state); - } - - @ModifyVariable(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/color/world/BiomeColors;getWaterColor(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/util/math/BlockPos;)I")) - public Sprite[] sprites(Sprite[] sprites) { - FluidState state = stateThreadLocal.get(); - if (state.getFluid() instanceof FluidWrapper) { - return spriteMap.getOrDefault(((FluidWrapper) state.getFluid()).getFluid(), waterSprites); - } - return sprites; - } - - @ModifyVariable(at = @At(value = "INVOKE", target = "net/minecraft/client/render/block/FluidRenderer.isSameFluid(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;Lnet/minecraft/fluid/FluidState;)Z"), method = "render", ordinal = 0) - public boolean isLava(boolean chk) { - return chk || (stateThreadLocal.get() != null && !FluidTags.WATER.contains(stateThreadLocal.get().getFluid())); - } - - @Inject(at = @At("RETURN"), method = "render") - public void removeLocal(BlockRenderView view, BlockPos pos, VertexConsumer bufferBuilder, FluidState state, CallbackInfoReturnable info) { - stateThreadLocal.remove(); - } - - @ModifyVariable(at = @At(value = "CONSTANT", args = "intValue=16", ordinal = 0, shift = At.Shift.BEFORE), method = "render", ordinal = 0) - public int tint(int chk) { - return !(stateThreadLocal.get().getFluid() instanceof FluidWrapper) ? chk : -1; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinMinecraftClient.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinMinecraftClient.java deleted file mode 100644 index c85e0b3..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinMinecraftClient.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.client; - -import net.minecraft.client.MinecraftClient; -import org.sandboxpowered.api.client.Client; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(MinecraftClient.class) -@Implements(@Interface(iface = Client.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinMinecraftClient { - -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinModelLoader.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinModelLoader.java deleted file mode 100644 index 41c6683..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinModelLoader.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.client; - -import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.util.SpriteIdentifier; -import net.minecraft.fluid.Fluid; -import net.minecraft.screen.PlayerScreenHandler; -import net.minecraft.util.registry.Registry; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.FluidWrapper; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.Collection; -import java.util.Set; - -@Mixin(ModelLoader.class) -public class MixinModelLoader { - @Redirect(method = "", at = @At(value = "INVOKE", target = "Ljava/util/Set;addAll(Ljava/util/Collection;)Z")) - public boolean addAll(Set set, Collection set2) { - for (Fluid fluid : Registry.FLUID) { - if (fluid instanceof FluidWrapper) { - set.add(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, WrappingUtil.convert(((FluidWrapper) fluid).getFluid().getTexturePath(false)))); - set.add(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, WrappingUtil.convert(((FluidWrapper) fluid).getFluid().getTexturePath(true)))); - } - } - return set.addAll(set2); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinRenderLayers.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinRenderLayers.java deleted file mode 100644 index b172330..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinRenderLayers.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.client; - -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.RenderLayers; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.BlockWrapper; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(RenderLayers.class) -public class MixinRenderLayers { - @Inject(method = "getBlockLayer", at = @At(value = "HEAD"), cancellable = true) - private static void getBlockLayer(BlockState state, CallbackInfoReturnable info) { - if (state.getBlock() instanceof BlockWrapper) - info.setReturnValue(getRenderLayerFromState(WrappingUtil.convert(state))); - } - - @Inject(method = "getMovingBlockLayer", at = @At(value = "HEAD"), cancellable = true) - private static void getMovingBlockLayer(BlockState state, CallbackInfoReturnable info) { - if (state.getBlock() instanceof BlockWrapper) { - RenderLayer layer = getRenderLayerFromState(WrappingUtil.convert(state)); - if (layer == RenderLayer.getTranslucent()) - layer = RenderLayer.getTranslucentMovingBlock(); - info.setReturnValue(layer); - } - } - - private static RenderLayer getRenderLayerFromState(org.sandboxpowered.api.state.BlockState state) { - //TODO: Maybe allow blocks to fully say what render layer they want even if its custom. - Block.BlockRenderLayer layer = state.getRenderLayer(WrappingUtil.convert(MinecraftClient.getInstance().options.graphicsMode)); - switch (layer) { - case SOLID: - return RenderLayer.getSolid(); - case TRANSPARENT: - return RenderLayer.getTranslucent(); - case CUTOUT: - return RenderLayer.getCutout(); - case CUTOUT_MIPPED: - return RenderLayer.getCutoutMipped(); - } - return RenderLayer.getSolid(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinWorldRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinWorldRenderer.java deleted file mode 100644 index a7378ee..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/client/MixinWorldRenderer.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.client; - -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.texture.TextureManager; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(WorldRenderer.class) -public class MixinWorldRenderer { - @Redirect(method = "renderWorldBorder", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V")) - public void bindTexture(TextureManager manager, Identifier identifier) { - SandboxConfig.WorldBorder border = SandboxConfig.worldBorder.getEnum(SandboxConfig.WorldBorder.class); - if (border.getTexture() != null) - identifier = border.getTexture(); - manager.bindTexture(identifier); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinEnchantment.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinEnchantment.java deleted file mode 100644 index 13bd5ed..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinEnchantment.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.enchant; - -import org.sandboxpowered.api.enchantment.Enchantment; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.enchantment.Enchantment.class) -@Implements(@Interface(iface = Enchantment.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinEnchantment { - - @Shadow - public abstract boolean isCursed(); - - @Shadow - public abstract String getTranslationKey(); - - @Shadow - public abstract boolean isAcceptableItem(net.minecraft.item.ItemStack stack); - - @Shadow - public abstract boolean isTreasure(); - - @Shadow - public abstract int getMinLevel(); - - @Shadow - public abstract int getMaxLevel(); - - public int sbx$getMinimumLevel() { - return this.getMinLevel(); - } - - public int sbx$getMaximumLevel() { - return this.getMaxLevel(); - } - - public boolean sbx$isAcceptableItem(ItemStack stack) { - return this.isAcceptableItem(WrappingUtil.convert(stack)); - } - - public boolean sbx$isCurse() { - return this.isCursed(); - } - - public boolean sbx$isTreasure() { - return this.isTreasure(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinSandboxEnchantment.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinSandboxEnchantment.java deleted file mode 100644 index 91ecec6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/enchant/MixinSandboxEnchantment.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.enchant; - -import org.sandboxpowered.api.enchantment.BaseEnchantment; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.wrapper.EnchantmentWrapper; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(value = BaseEnchantment.class, remap = false) -@Unique -public abstract class MixinSandboxEnchantment implements SandboxInternal.WrappedInjection { - private EnchantmentWrapper sandboxWrappedInjection; - - @Override - public final EnchantmentWrapper getInjectionWrapped() { - return sandboxWrappedInjection; - } - - @Override - public final void setInjectionWrapped(EnchantmentWrapper o) { - sandboxWrappedInjection = o; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntity.java deleted file mode 100644 index 7cd2280..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.entity; - -import net.minecraft.entity.EntityType; -import org.sandboxpowered.api.entity.Entity; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.entity.Entity.class) -@Implements(@Interface(iface = Entity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinEntity { - - @Shadow - public abstract EntityType getType(); - - @Shadow - public abstract boolean isSneaking(); - - public Entity.Type sbx$getType() { - return (Entity.Type) getType(); - } - - public boolean sbx$isSneaking() { - return isSneaking(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntityType.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntityType.java deleted file mode 100644 index 731b275..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinEntityType.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.entity; - -import net.minecraft.entity.EntityType; -import org.sandboxpowered.api.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(EntityType.class) -public class MixinEntityType implements Entity.Type { - -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinLivingEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinLivingEntity.java deleted file mode 100644 index 6b6dd2c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinLivingEntity.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.entity; - -import net.minecraft.entity.EquipmentSlot; -import org.sandboxpowered.api.entity.LivingEntity; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.entity.LivingEntity.class) -@Implements(@Interface(iface = LivingEntity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinLivingEntity { - @Shadow - public abstract float getHealth(); - - @Shadow - public abstract void setHealth(float hp); - - @Shadow - public abstract net.minecraft.item.ItemStack getEquippedStack(EquipmentSlot equipmentSlot); - - @Shadow - public abstract void equipStack(EquipmentSlot equipmentSlot, net.minecraft.item.ItemStack itemStack); - - @Shadow - public abstract void swingHand(net.minecraft.util.Hand hand, boolean bl); - - @Shadow - public abstract net.minecraft.item.ItemStack getStackInHand(net.minecraft.util.Hand hand); - - @Shadow - public abstract void setStackInHand(net.minecraft.util.Hand hand, net.minecraft.item.ItemStack itemStack); - - public void sbx$setHealth(float health) { - this.setHealth(health); - } - - public float sbx$getHealth() { - return this.getHealth(); - } - - public ItemStack sbx$getEquipped(LivingEntity.EquipmentSlot slot) { - return WrappingUtil.convert(getEquippedStack(WrappingUtil.convert(slot))); - } - - public void sbx$equip(LivingEntity.EquipmentSlot slot, ItemStack stack) { - equipStack(WrappingUtil.convert(slot), WrappingUtil.convert(stack)); - } - - public void sbx$swing(Hand hand, boolean updateSelf) { - swingHand( - WrappingUtil.convert(hand), - updateSelf - ); - } - - public void sbx$setHeld(Hand hand, ItemStack stack) { - setStackInHand(WrappingUtil.convert(hand), WrappingUtil.convert(stack)); - } - - public ItemStack sbx$getHeld(Hand hand) { - return WrappingUtil.convert(getStackInHand(WrappingUtil.convert(hand))); - } - -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinPlayerEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinPlayerEntity.java deleted file mode 100644 index 673c520..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinPlayerEntity.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.entity; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.world.World; -import org.sandboxpowered.api.entity.player.Hand; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.nbt.CompoundTag; -import org.sandboxpowered.api.util.text.Text; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.entity.player.PlayerEntity.class) -@Implements(@Interface(iface = PlayerEntity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinPlayerEntity extends LivingEntity { - @Shadow - @Final - public PlayerInventory inventory; - private boolean sbxIgnoreSleeping; - - public MixinPlayerEntity(EntityType type, World world) { - super(type, world); - } - - @Shadow - public abstract void sendMessage(net.minecraft.text.Text text, boolean bl); - - public void sbx$sendChatMessage(Text text) { - this.sendMessage(WrappingUtil.convert(text), false); - } - - public void sbx$sendOverlayMessage(Text text) { - this.sendMessage(WrappingUtil.convert(text), true); - } - - public void sbx$openContainer(Identity id, CompoundTag data) { - // NO-OP - } - - public boolean sbx$isSleeping() { - return this.getSleepingPosition().isPresent(); - } - - public boolean sbx$isSleepingIgnored() { - return sbxIgnoreSleeping; - } - - public void sbx$setSleepingIgnored(boolean ignored) { - this.sbxIgnoreSleeping = ignored; - } - - public ItemStack sbx$getHeld(Hand hand) { - return WrappingUtil.convert(hand == Hand.MAIN_HAND ? inventory.getMainHandStack() : inventory.offHand.get(0)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinServerPlayerEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinServerPlayerEntity.java deleted file mode 100644 index 7804655..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/entity/MixinServerPlayerEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.entity; - -import com.mojang.authlib.GameProfile; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(ServerPlayerEntity.class) -@Implements(@Interface(iface = PlayerEntity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -public abstract class MixinServerPlayerEntity extends net.minecraft.entity.player.PlayerEntity { - public MixinServerPlayerEntity(World world, BlockPos blockPos, float f, GameProfile gameProfile) { - super(world, blockPos, f, gameProfile); - } -// -// public void sbx$openContainer(Identity id, CompoundTag dataMono) { -// incrementContainerSyncId(); -// int syncId = containerSyncId; -// CompoundTag data = dataMono == null ? CompoundTag.create() : dataMono; -// -// ContainerOpenPacket packet = new ContainerOpenPacket(id, syncId, data); -// NetworkManager.sendTo(packet, this); -// -// Registries.CONTAINER.get(id).ifPresent(factory -> { -// Container container = factory.create(id, new V2SInventory(inventory), data); -// -// this.container = new ContainerWrapper(null, syncId, container); -// this.container.addListener((ServerPlayerEntity) (Object) this); -// }); -// } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinBaseFluid.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinBaseFluid.java deleted file mode 100644 index 402bd89..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinBaseFluid.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.fluid; - -import net.minecraft.fluid.FlowableFluid; -import net.minecraft.fluid.Fluid; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(FlowableFluid.class) -public abstract class MixinBaseFluid extends Fluid implements SandboxInternal.BaseFluid { - @Shadow - protected abstract boolean isInfinite(); - - @Override - public boolean sandboxInfinite() { - return isInfinite(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluid.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluid.java deleted file mode 100644 index 8f10e8b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluid.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.fluid; - -import net.minecraft.fluid.FlowableFluid; -import net.minecraft.fluid.Fluids; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.state.FluidState; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Vec3d; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.StateFactoryImpl; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Optional; - -@Mixin(net.minecraft.fluid.Fluid.class) -@Implements(@Interface(iface = Fluid.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"ConstantConditions", "java:S100", "java:S1610"}) -public abstract class MixinFluid implements SandboxInternal.StateFactoryHolder { - @Shadow - @Final - protected net.minecraft.state.StateManager stateManager; - private StateFactory sandboxFactory; - - @SuppressWarnings("unchecked") - @Inject(method = "", at = @At("RETURN")) - private void constructor(CallbackInfo info) { - sandboxFactory = new StateFactoryImpl<>(this.stateManager, Fluid.class::cast, FluidState.class::cast); - ((SandboxInternal.StateFactory) this.stateManager).setSboxFactory(sandboxFactory); - } - - @Override - public StateFactory getSandboxStateFactory() { - return sandboxFactory; - } - - @Shadow - public abstract net.minecraft.fluid.FluidState getDefaultState(); - - @Shadow - public abstract boolean isStill(net.minecraft.fluid.FluidState var1); - - @Shadow - protected abstract net.minecraft.block.BlockState toBlockState(net.minecraft.fluid.FluidState var1); - - @Shadow - public abstract net.minecraft.item.Item getBucketItem(); - - @Shadow - protected abstract net.minecraft.util.math.Vec3d getVelocity(BlockView var1, BlockPos var2, net.minecraft.fluid.FluidState var3); - - public FluidState sbx$getBaseState() { - return WrappingUtil.convert(getDefaultState()); - } - - @SuppressWarnings("unchecked") - public StateFactory sbx$getStateFactory() { - return ((SandboxInternal.StateFactory) stateManager).getSboxFactory(); - } - - public boolean sbx$isStill(FluidState state) { - return isStill(WrappingUtil.convert(state)); - } - - - public BlockState sbx$asBlockState(FluidState state) { - return (BlockState) this.toBlockState(WrappingUtil.convert(state)); - } - - public Fluid sbx$asStill() { - if ((Object) this instanceof FlowableFluid) - return WrappingUtil.convert(((FlowableFluid) (Object) this).getStill()); - return WrappingUtil.convert(Fluids.EMPTY); - } - - - public Fluid sbx$asFlowing() { - if ((Object) this instanceof FlowableFluid) - return WrappingUtil.convert(((FlowableFluid) (Object) this).getFlowing()); - return WrappingUtil.convert(Fluids.EMPTY); - } - - public boolean sbx$isInfinite() { - if ((Object) this instanceof FlowableFluid) - return ((SandboxInternal.BaseFluid) this).sandboxInfinite(); - return false; - } - - public Item sbx$asBucket() { - return WrappingUtil.convert(getBucketItem()); - } - - public Optional sbx$getVelocity(WorldReader world, Position position, FluidState state) { - return Optional.of(getVelocity( - (BlockView) world, - (BlockPos) position, - WrappingUtil.convert(state) - )).map(vec -> (Vec3d) vec); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluidState.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluidState.java deleted file mode 100644 index 49e1e54..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinFluidState.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.fluid; - -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.state.FluidState; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.fluid.FluidState.class) -@Implements(@Interface(iface = FluidState.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinFluidState { - @Shadow - public abstract net.minecraft.fluid.Fluid getFluid(); - - public Fluid sbx$getFluid() { - return WrappingUtil.convert(getFluid()); - } - - public BlockState sbx$asBlockState() { - return sbx$getFluid().asBlockState((FluidState) this); - } - - public boolean sbx$isStill() { - return sbx$getFluid().isStill((FluidState) this); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinSandboxFluid.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinSandboxFluid.java deleted file mode 100644 index 754a267..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/fluid/MixinSandboxFluid.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.fluid; - -import org.sandboxpowered.api.fluid.BaseFluid; -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(value = BaseFluid.class, remap = false) -public abstract class MixinSandboxFluid implements SandboxInternal.WrappedInjection { - private Fluid sandboxWrappedInjection; - - @Override - public final Fluid getInjectionWrapped() { - return sandboxWrappedInjection; - } - - @Override - public final void setInjectionWrapped(Fluid o) { - sandboxWrappedInjection = o; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinBlockItem.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinBlockItem.java deleted file mode 100644 index 0c4c9a2..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinBlockItem.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.item; - -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.item.BlockItem; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.item.BlockItem.class) -@Implements(@Interface(iface = BlockItem.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinBlockItem { - @Shadow - public abstract net.minecraft.block.Block getBlock(); - - public Block sbx$asBlock() { - return WrappingUtil.convert(getBlock()); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItem.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItem.java deleted file mode 100644 index bf385bb..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItem.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.item; - -import org.sandboxpowered.api.item.Item; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(net.minecraft.item.Item.class) -@Implements(@Interface(iface = Item.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public class MixinItem { - -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItemStack.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItemStack.java deleted file mode 100644 index 9d6d30f..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinItemStack.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.item; - -import net.minecraft.block.BlockState; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.nbt.ListTag; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.enchantment.Enchantment; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.util.nbt.CompoundTag; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -@Mixin(net.minecraft.item.ItemStack.class) -@Implements(@Interface(iface = ItemStack.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"EqualsBetweenInconvertibleTypes", "java:S100", "java:S1610"}) -public abstract class MixinItemStack { - - @Shadow - public abstract boolean isEmpty(); - - @Shadow - public abstract net.minecraft.item.Item getItem(); - - @Shadow - public abstract int getCount(); - - @Shadow - public abstract void setCount(int amount); - - @Shadow - public abstract void decrement(int amount); - - @Shadow - public abstract void increment(int amount); - - @Shadow - public abstract net.minecraft.util.Rarity getRarity(); - - @Shadow - public abstract boolean hasTag(); - - @Shadow - @Nullable - public abstract net.minecraft.nbt.CompoundTag getTag(); - - @Shadow - public abstract void setTag(@Nullable net.minecraft.nbt.CompoundTag tag); - - @Shadow - public abstract net.minecraft.nbt.CompoundTag getOrCreateTag(); - - @Shadow - @Nullable - public abstract net.minecraft.nbt.CompoundTag getSubTag(String string); - - @Shadow - public abstract net.minecraft.nbt.CompoundTag getOrCreateSubTag(String string); - - @Shadow - public abstract int getMaxCount(); - - @Shadow - public abstract boolean isItemEqual(net.minecraft.item.ItemStack stack); - - @Shadow - public abstract net.minecraft.item.ItemStack copy(); - - @Shadow - public abstract boolean isItemEqualIgnoreDamage(net.minecraft.item.ItemStack stack); - - @Shadow - public abstract net.minecraft.nbt.CompoundTag toTag(net.minecraft.nbt.CompoundTag tag); - - @Shadow - public abstract boolean isDamaged(); - - @Shadow - public abstract boolean isDamageable(); - - @Shadow - public abstract int getMaxDamage(); - - @Shadow - public abstract int getDamage(); - - @Shadow - public abstract ListTag getEnchantments(); - - public boolean sbx$isEmpty() { - return this.isEmpty(); - } - - public Item sbx$getItem() { - return WrappingUtil.convert(getItem()); - } - - public int sbx$getCount() { - return this.getCount(); - } - - public ItemStack sbx$shrink(int amount) { - this.decrement(amount); - return (ItemStack) this; - } - - public ItemStack sbx$grow(int amount) { - this.increment(amount); - return (ItemStack) this; - } - - public ItemStack sbx$setCount(int amount) { - this.setCount(amount); - return (ItemStack) this; - } - - public int sbx$getLevel(Enchantment enchantment) { - return EnchantmentHelper.getLevel(WrappingUtil.convert(enchantment), (net.minecraft.item.ItemStack) (Object) this); - } - - @Inject(method = "isEffectiveOn", at = @At("HEAD"), cancellable = true) - public void isEffectiveOn(BlockState state, CallbackInfoReturnable info) { - if (getItem() instanceof SandboxInternal.IItemWrapper) { - info.setReturnValue(((SandboxInternal.IItemWrapper) getItem()).getItem().isEffectiveOn(WrappingUtil.convert((net.minecraft.item.ItemStack) (Object) this), WrappingUtil.convert(state))); - } - } - - public Set sbx$getEnchantments() { - if (isEmpty()) - return Collections.emptySet(); - Set set = new HashSet<>(); - ListTag listTag = getEnchantments(); - for (int i = 0; i < listTag.size(); ++i) { - net.minecraft.nbt.CompoundTag tag = listTag.getCompound(i); - String string = tag.getString("id"); - Registry.ENCHANTMENT.getOrEmpty(Identifier.tryParse(string)).ifPresent(enchantment -> set.add(WrappingUtil.convert(enchantment))); - } - return set; - } - - public boolean sbx$hasTag() { - return hasTag(); - } - - public CompoundTag sbx$getTag() { - return (CompoundTag) getTag(); - } - - public void sbx$setTag(CompoundTag tag) { - setTag((net.minecraft.nbt.CompoundTag) tag); - } - - public CompoundTag sbx$getChildTag(String key) { - return (CompoundTag) getSubTag(key); - } - - public CompoundTag sbx$getOrCreateChildTag(String key) { - return (CompoundTag) getOrCreateSubTag(key); - } - - public CompoundTag sbx$getOrCreateTag() { - return (CompoundTag) getOrCreateTag(); - } - - public int sbx$getMaxCount() { - return getMaxCount(); - } - - public ItemStack sbx$copy() { - return WrappingUtil.convert(copy()); - } - - public boolean sbx$isEqualTo(ItemStack stack) { - if (this == stack) { - return true; - } else { - return (!this.sbx$isEmpty() && !stack.isEmpty()) && isItemEqual(WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class)); - } - } - - public boolean sbx$isEqualToIgnoreDurability(ItemStack stack) { - if (this == stack) { - return true; - } else { - return (!this.sbx$isEmpty() && !stack.isEmpty()) && isItemEqualIgnoreDamage(WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class)); - } - } - - public boolean sbx$areTagsEqual(ItemStack stack) { - if (this == stack) { - return true; - } else if ((sbx$isEmpty() || stack.isEmpty()) || (!hasTag() && stack.hasTag())) { - return false; - } - return (!sbx$hasTag() && !stack.hasTag()) || Objects.equals(getTag(), stack.getTag()); - } - - public CompoundTag sbx$asTag() { - return (CompoundTag) toTag(new net.minecraft.nbt.CompoundTag()); - } - - public boolean sbx$isDamaged() { - return isDamaged(); - } - - public boolean sbx$isDamageable() { - return isDamageable(); - } - - public int sbx$getMaxDamage() { - return getMaxDamage(); - } - - public int sbx$getDamage() { - return getDamage(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinSandboxItem.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinSandboxItem.java deleted file mode 100644 index d256c6c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/item/MixinSandboxItem.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.item; - -import org.sandboxpowered.api.item.BaseItem; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(value = BaseItem.class, remap = false) -@Unique -public abstract class MixinSandboxItem implements SandboxInternal.WrappedInjection { - private SandboxInternal.IItemWrapper sandboxWrappedInjection; - - @Override - public final SandboxInternal.IItemWrapper getInjectionWrapped() { - return sandboxWrappedInjection; - } - - @Override - public final void setInjectionWrapped(SandboxInternal.IItemWrapper o) { - sandboxWrappedInjection = o; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinCompoundTag.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinCompoundTag.java deleted file mode 100644 index 648836b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinCompoundTag.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.nbt; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.math.Position; -import org.spongepowered.asm.mixin.*; - -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -@Mixin(CompoundTag.class) -@Implements(@Interface(iface = org.sandboxpowered.api.util.nbt.CompoundTag.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"unchecked", "java:S100", "java:S1610"}) -public abstract class MixinCompoundTag implements Tag { - - @Shadow - public abstract int getSize(); - - @Shadow - public abstract Set getKeys(); - - @Shadow - public abstract int getInt(String key); - - @Shadow - public abstract void putInt(String key, int i); - - @Shadow - public abstract int[] getIntArray(String key); - - @Shadow - public abstract void putIntArray(String key, int[] ints); - - @Shadow - public abstract String getString(String key); - - @Shadow - public abstract void putString(String key, String string); - - @Shadow - public abstract double getDouble(String key); - - @Shadow - public abstract byte getByte(String key); - - @Shadow - public abstract void putByte(String key, byte b); - - @Shadow - public abstract byte[] getByteArray(String key); - - @Shadow - public abstract void putByteArray(String key, byte[] bytes); - - @Shadow - public abstract long getLong(String key); - - @Shadow - public abstract void putLong(String key, long l); - - @Shadow - public abstract boolean getBoolean(String key); - - @Shadow - public abstract void putBoolean(String key, boolean b); - - @Shadow - public abstract void putDouble(String key, double d); - - @Shadow - public abstract void remove(String key); - - @Shadow - @Nullable - public abstract Tag put(String key, Tag tag); - - @Shadow - public abstract ListTag getList(String key, int i); - - @Shadow - public abstract boolean contains(String key); - - @Shadow - public abstract UUID getUuid(String key); - - @Shadow - public abstract void putUuid(String key, UUID uUID); - - @SuppressWarnings("java:S100") - public int sbx$size() { - return getSize(); - } - - - public Collection sbx$getKeys() { - return getKeys(); - } - - - public int sbx$getInt(String key) { - return getInt(key); - } - - - public void sbx$setInt(String key, int i) { - putInt(key, i); - } - - - public int[] sbx$getIntArray(String key) { - return getIntArray(key); - } - - - public void sbx$setIntArray(String key, int[] i) { - putIntArray(key, i); - } - - - public String sbx$getString(String key) { - return getString(key); - } - - - public void sbx$setString(String key, String s) { - putString(key, s); - } - - - public double sbx$getDouble(String key) { - return getDouble(key); - } - - - public void sbx$setDouble(String key, double d) { - putDouble(key, d); - } - - - public byte sbx$getByte(String key) { - return getByte(key); - } - - - public void sbx$setByte(String key, byte b) { - putByte(key, b); - } - - - public byte[] sbx$getByteArray(String key) { - return getByteArray(key); - } - - - public void sbx$setByteArray(String key, byte[] b) { - putByteArray(key, b); - } - - public long sbx$getLong(String key) { - return getLong(key); - } - - public void sbx$setLong(String key, long l) { - putLong(key, l); - } - - public boolean sbx$getBoolean(String key) { - return getBoolean(key); - } - - public void sbx$setBoolean(String key, boolean bool) { - putBoolean(key, bool); - } - - public UUID sbx$getUUID(String key) { - return getUuid(key); - } - - public void sbx$setUUID(String key, UUID uuid) { - putUuid(key, uuid); - } - - public boolean sbx$remove(String key) { - if (contains(key)) - return false; - remove(key); - return true; - } - - public void sbx$setIdentity(String key, Identity identity) { - sbx$setString(key + "_namespace", identity.getNamespace()); - sbx$setString(key + "_path", identity.getPath()); - } - - public Identity sbx$getIdentity(String key) { - return Identity.of(sbx$getString(key + "_namespace"), sbx$getString(key + "_path")); - } - - public void sbx$setPosition(String key, Position position) { - sbx$setInt(key + "_x", position.getX()); - sbx$setInt(key + "_y", position.getY()); - sbx$setInt(key + "_z", position.getZ()); - } - - public Position sbx$getPosition(String key) { - return Position.create(sbx$getInt(key + "_x"), sbx$getInt(key + "_z"), sbx$getInt(key + "_y")); - } - - public void sbx$setList(String key, List list) { - ListTag tag; - @SuppressWarnings({"UnnessesaryLocalVariable", "rawtypes"}) List castedList = list; - if (castedList instanceof ListTag) { - tag = (ListTag) castedList; - } else { - tag = new ListTag(); - tag.addAll((Collection) castedList); - } - put(key, tag); - } - - public List sbx$getList(String key, Class tagType) { - int id = 0; - if (tagType == org.sandboxpowered.api.util.nbt.CompoundTag.class) { - id = 10; - } - ListTag tag = getList(key, id); - return (List) tag; - } - - public boolean sbx$contains(String key) { - return contains(key); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinTag.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinTag.java deleted file mode 100644 index dcd33a1..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/nbt/MixinTag.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.nbt; - -import org.sandboxpowered.api.util.nbt.Tag; -import org.spongepowered.asm.mixin.*; - -@Mixin(net.minecraft.nbt.Tag.class) -@Implements(@Interface(iface = Tag.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public interface MixinTag { - @Shadow - String asString(); - - default String sbx$asString() { - return asString(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/server/MixinMinecraftServer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/server/MixinMinecraftServer.java deleted file mode 100644 index 22d1b49..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/server/MixinMinecraftServer.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.server; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.registry.RegistryKey; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.server.Server; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.world.World; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -@Implements(@Interface(iface = Server.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinMinecraftServer { - @Shadow - @Nullable - public abstract ServerWorld getWorld(RegistryKey registryKey); - - @Inject(method = "", at = @At("RETURN")) - public void constructor(CallbackInfo info) { -// SandboxCommon.server = (Server) this; TODO - } - - public World sbx$getWorld(Identity identity) { - throw new UnsupportedOperationException("Unable to use getWorld"); //TODO -// return (World) getWorld(DimensionType.byId(WrappingUtil.convert(identity))); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinBox.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinBox.java deleted file mode 100644 index e7bd6aa..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinBox.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.shape; - -import net.minecraft.util.math.Box; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(Box.class) -@Implements(@Interface(iface = org.sandboxpowered.api.shape.Box.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public class MixinBox { - -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinVoxelShape.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinVoxelShape.java deleted file mode 100644 index 1c0c492..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/shape/MixinVoxelShape.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.shape; - -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import org.sandboxpowered.api.shape.Box; -import org.sandboxpowered.api.shape.Shape; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.math.ShapeCombination; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -import java.util.Collections; -import java.util.List; - -@Mixin(VoxelShape.class) -@Implements(@Interface(iface = Shape.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinVoxelShape { - @Shadow - public abstract boolean isEmpty(); - - @Shadow - public abstract net.minecraft.util.math.Box getBoundingBox(); - - @Shadow - public abstract VoxelShape simplify(); - - @Shadow - public abstract VoxelShape offset(double d, double e, double f); - - @Shadow - public abstract VoxelShape getFace(net.minecraft.util.math.Direction direction); - - @Shadow - protected abstract boolean contains(double d, double e, double f); - - public Box sbx$getBoundingBox() { - return WrappingUtil.convert(getBoundingBox()); - } - - public boolean sbx$isEmpty() { - return isEmpty(); - } - - public Shape sbx$offset(double x, double y, double z) { - return WrappingUtil.convert(offset(x, y, z)); - } - - public Shape sbx$simplify() { - return WrappingUtil.convert(simplify()); - } - - public List sbx$getBoxes() { - return Collections.emptyList(); - } - - public Shape sbx$getFace(Direction direction) { - return WrappingUtil.convert(getFace(WrappingUtil.convert(direction))); - } - - public boolean sbx$contains(double x, double y, double z) { - return contains(x, y, z); - } - - public Shape sbx$combine(Shape shape, ShapeCombination combination) { - return WrappingUtil.convert(VoxelShapes.combine(WrappingUtil.cast(this, VoxelShape.class), WrappingUtil.convert(shape), combination::combine)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinBlockState.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinBlockState.java deleted file mode 100644 index ee8d69e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinBlockState.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.state; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.MapCodec; -import net.minecraft.block.BlockState; -import net.minecraft.state.State; -import net.minecraft.state.property.Property; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(BlockState.class) -@Implements(@Interface(iface = org.sandboxpowered.api.state.BlockState.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinBlockState extends State { - public MixinBlockState(net.minecraft.block.Block object, ImmutableMap, Comparable> immutableMap, MapCodec mapCodec) { - super(object, immutableMap, mapCodec); - } - - public Block sbx$getBlock() { - return WrappingUtil.convert(this.owner); // Has to use the field otherwise causes a loop - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinState.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinState.java deleted file mode 100644 index 531ea80..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/state/MixinState.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.state; - -import net.minecraft.state.State; -import org.sandboxpowered.api.state.Property; -import org.sandboxpowered.api.state.PropertyContainer; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.sandboxpowered.sandbox.fabric.util.wrapper.EnumPropertyWrapper; -import org.spongepowered.asm.mixin.*; - -@Mixin(State.class) -@Implements(@Interface(iface = PropertyContainer.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinState { - @Shadow - public abstract > T get(net.minecraft.state.property.Property var1); - - @Shadow - public abstract , V extends T> Object with(net.minecraft.state.property.Property var1, V var2); - - @Shadow - public abstract > boolean contains(net.minecraft.state.property.Property property); - - public > T sbx$get(Property property) { - if (property instanceof EnumPropertyWrapper) { - return (T) ((EnumPropertyWrapper) property).getV2SFunction().apply(get(WrappingUtil.convert(property))); - } else { - return get(WrappingUtil.convert(property)); - } - } - - public > Object sbx$with(Property property, T value) { - if (property instanceof EnumPropertyWrapper) { - value = (T) ((EnumPropertyWrapper) property).getS2VFunction().apply(value); - } - return with(WrappingUtil.convert(property), value); - } - - public > boolean sbx$contains(Property property) { - return this.contains(WrappingUtil.convert(property)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/text/MixinText.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/text/MixinText.java deleted file mode 100644 index 38c259a..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/text/MixinText.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.text; - -import com.mojang.brigadier.Message; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(Text.class) -@Implements(@Interface(iface = org.sandboxpowered.api.util.text.Text.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public interface MixinText extends Message { - - @Shadow - String asString(); - - default void sbx$append(org.sandboxpowered.api.util.text.Text text) { - if (this instanceof MutableText) { - ((MutableText) this).append(WrappingUtil.convert(text)); - } - } - - default String sbx$asString() { - return this.asString(); - } - - default String sbx$asFormattedString() { - return asString(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinBlockPos.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinBlockPos.java deleted file mode 100644 index 0154bf0..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinBlockPos.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Position.Mutable; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -@Mixin(BlockPos.class) -@Implements(@Interface(iface = Position.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"ConstantConditions", "java:S100", "java:S1610"}) -public abstract class MixinBlockPos extends Vec3i { - public MixinBlockPos() { - super(0, 0, 0); - } - - public Mutable sbx$toMutable() { - return (Mutable) new BlockPos.Mutable(this.getX(), this.getY(), this.getZ()); - } - - public Position sbx$toImmutable() { - return (Position) this; - } - - public Position sbx$offset(Direction direction, int amount) { - return (Position) this.offset(WrappingUtil.convert(direction), amount); - } - - @Mixin(BlockPos.Mutable.class) - @Implements(@Interface(iface = Position.Mutable.class, prefix = "sbx$", remap = Interface.Remap.NONE)) - @Unique - public abstract static class MixinMutable extends BlockPos { - public MixinMutable() { - super(0, 0, 0); - } - - @Shadow - public abstract Mutable set(int x, int y, int z); - - public Position.Mutable sbx$toMutable() { - return (Position.Mutable) this; - } - - public Position sbx$toImmutable() { - return (Position) new BlockPos(this); - } - - public Position.Mutable sbx$set(int x, int y, int z) { - return (Position.Mutable) this.set(x, y, z); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinIdentifier.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinIdentifier.java deleted file mode 100644 index 2bc4a6b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinIdentifier.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import net.minecraft.util.Identifier; -import org.sandboxpowered.api.util.Identity; -import org.spongepowered.asm.mixin.*; - -@Mixin(Identifier.class) -@Implements(@Interface(iface = Identity.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings({"java:S100","java:S1610"}) -public abstract class MixinIdentifier { - @Shadow - public abstract String getNamespace(); - - @Shadow - public abstract String getPath(); - - public String sbx$getNamespace() { - return getNamespace(); - } - - public String sbx$getPath() { - return getPath(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinProperty.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinProperty.java deleted file mode 100644 index 5b81f94..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinProperty.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import org.sandboxpowered.api.state.Property; -import org.spongepowered.asm.mixin.*; - -import java.util.Collection; -import java.util.Optional; - -@Mixin(net.minecraft.state.property.Property.class) -@Implements(@Interface(iface = Property.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -@SuppressWarnings("java:S100") -public abstract class MixinProperty> { - @Shadow - public abstract String getName(); - - @Shadow - public abstract Collection getValues(); - - @Shadow - public abstract String name(T var1); - - @Shadow - public abstract Class getType(); - - @Shadow - public abstract Optional parse(String var1); - - public String sbx$getName() { - return getName(); - } - - public String sbx$getName(T value) { - return name(value); - } - - public Collection sbx$getValues() { - return getValues(); - } - - public Class sbx$getValueType() { - return getType(); - } - - public Optional sbx$getValue(String name) { - return parse(name); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3d.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3d.java deleted file mode 100644 index 6b9283a..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3d.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import net.minecraft.util.math.Vec3d; -import org.spongepowered.asm.mixin.*; - -@Mixin(Vec3d.class) -@Implements(@Interface(iface = org.sandboxpowered.api.util.math.Vec3d.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinVec3d { - @Shadow - public abstract double getX(); - - @Shadow - public abstract double getY(); - - @Shadow - public abstract double getZ(); - - @Shadow - public abstract Vec3d add(double x, double y, double z); - - public double sbx$getX() { - return this.getX(); - } - - public double sbx$getY() { - return this.getY(); - } - - public double sbx$getZ() { - return this.getZ(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3i.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3i.java deleted file mode 100644 index b594e00..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVec3i.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import net.minecraft.util.math.Vec3i; -import org.spongepowered.asm.mixin.*; - -@Mixin(Vec3i.class) -@Implements(@Interface(iface = org.sandboxpowered.api.util.math.Vec3i.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinVec3i { - @Shadow - public abstract int getX(); - - @Shadow - public abstract int getY(); - - @Shadow - public abstract int getZ(); - - public int sbx$getX() { - return this.getX(); - } - - public int sbx$getY() { - return this.getY(); - } - - public int sbx$getZ() { - return this.getZ(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVector3f.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVector3f.java deleted file mode 100644 index 1babd5d..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/util/MixinVector3f.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.util; - -import net.minecraft.client.util.math.Vector3f; -import org.sandboxpowered.api.util.math.Vec3f; -import org.spongepowered.asm.mixin.*; - -@Mixin(Vector3f.class) -@Implements(@Interface(iface = Vec3f.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinVector3f { - @Shadow - public abstract float getX(); - - @Shadow - public abstract float getY(); - - @Shadow - public abstract float getZ(); - - public float sbx$getX() { - return this.getX(); - } - - public float sbx$getY() { - return this.getY(); - } - - public float sbx$getZ() { - return this.getZ(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinBlockView.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinBlockView.java deleted file mode 100644 index f4001a7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinBlockView.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.world; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.shape.Box; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.state.FluidState; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.stream.Stream; - -@Mixin(BlockView.class) -public interface MixinBlockView extends WorldReader { - @Shadow - net.minecraft.block.BlockState getBlockState(BlockPos pos); - - @Shadow - @Nullable - net.minecraft.block.entity.BlockEntity getBlockEntity(BlockPos var1); - - @Shadow - net.minecraft.fluid.FluidState getFluidState(BlockPos blockPos); - - @Override - default BlockState getBlockState(Position position) { - return WrappingUtil.convert(this.getBlockState(WrappingUtil.convert(position))); - } - - @Override - default FluidState getFluidState(Position position) { - return WrappingUtil.convert(getFluidState(WrappingUtil.convert(position))); - } - - @Override - @Nullable - default BlockEntity getBlockEntity(Position position) { - return WrappingUtil.convert(this.getBlockEntity(WrappingUtil.convert(position))); - } - - @Override - default Stream getEntitiesWithin(Box box) { - return Stream.empty(); - } - - @Override - default Stream getEntitiesWithin(Box box, Class filter) { - return Stream.empty(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinModifiableWorld.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinModifiableWorld.java deleted file mode 100644 index f84c636..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinModifiableWorld.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.world; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ModifiableWorld; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.BlockFlag; -import org.sandboxpowered.api.world.WorldWriter; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(ModifiableWorld.class) -public interface MixinModifiableWorld extends WorldWriter { - @Shadow - boolean setBlockState(BlockPos var1, net.minecraft.block.BlockState var2, int var3); - - @Shadow - boolean breakBlock(BlockPos blockPos, boolean bl, @Nullable net.minecraft.entity.Entity entity); - - @Override - default boolean setBlockState(Position position, BlockState state, BlockFlag... flags) { - return setBlockState(WrappingUtil.convert(position), WrappingUtil.convert(state), WrappingUtil.convert(flags)); - } - - @Override - default boolean breakBlock(Position position, boolean drop, @Nullable Entity entity) { - - return breakBlock(WrappingUtil.convert(position), drop, WrappingUtil.convert(entity)); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinWorld.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinWorld.java deleted file mode 100644 index d75f8b6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/impl/world/MixinWorld.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.impl.world; - -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.shape.Box; -import org.sandboxpowered.api.util.Side; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; -import org.spongepowered.asm.mixin.*; - -import java.util.List; -import java.util.Objects; -import java.util.function.Predicate; -import java.util.stream.Stream; - -@Mixin(World.class) -@Implements(@Interface(iface = org.sandboxpowered.api.world.World.class, prefix = "sbx$", remap = Interface.Remap.NONE)) -@Unique -public abstract class MixinWorld { - @Shadow - public abstract boolean isClient(); - - @Shadow - public abstract List getOtherEntities(net.minecraft.entity.@Nullable Entity entity, net.minecraft.util.math.Box box, @Nullable Predicate predicate); - - public Side sbx$getSide() { - return this.isClient() ? Side.CLIENT : Side.SERVER; - } - - public Stream sbx$getEntitiesWithin(Box box) { - return getOtherEntities(null, WrappingUtil.convert(box), null).stream().map(WrappingUtil::convert); - } - - public Stream sbx$getEntitiesWithin(Box box, Class filter) { - return getOtherEntities(null, WrappingUtil.convert(box), null).stream().map(e -> { - Entity it = WrappingUtil.convert(e); - return it.getClass().isAssignableFrom(filter) ? filter.cast(it) : null; - }).filter(Objects::nonNull); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinAbstractRedstoneGateBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinAbstractRedstoneGateBlock.java deleted file mode 100644 index 109dc43..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinAbstractRedstoneGateBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.AbstractRedstoneGateBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(AbstractRedstoneGateBlock.class) -public class MixinAbstractRedstoneGateBlock { - @Redirect(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinConcretePowderBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinConcretePowderBlock.java deleted file mode 100644 index c69e1c7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinConcretePowderBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.ConcretePowderBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ConcretePowderBlock.class) -public class MixinConcretePowderBlock { - @Redirect(method = "hardensOnAnySide", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralBlockBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralBlockBlock.java deleted file mode 100644 index 13a4610..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralBlockBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.CoralBlockBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CoralBlockBlock.class) -public class MixinCoralBlockBlock { - @Redirect(method = "isInWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralParentBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralParentBlock.java deleted file mode 100644 index b8609c2..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinCoralParentBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.CoralBlockBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CoralBlockBlock.class) -public class MixinCoralParentBlock { - @Redirect(method = "isInWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFireBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFireBlock.java deleted file mode 100644 index ce86c4e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFireBlock.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.FireBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(FireBlock.class) -public class MixinFireBlock { - @Redirect(method = "getStateForPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "areBlocksAroundFlammable", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "getBurnChance(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values3() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFluidBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFluidBlock.java deleted file mode 100644 index 1e945ba..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFluidBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.FluidBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(FluidBlock.class) -public class MixinFluidBlock { - @Redirect(method = "receiveNeighborFluids", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFrostedIceBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFrostedIceBlock.java deleted file mode 100644 index 7c54fec..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinFrostedIceBlock.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.FrostedIceBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(FrostedIceBlock.class) -public class MixinFrostedIceBlock { - @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "canMelt", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinLeavesBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinLeavesBlock.java deleted file mode 100644 index 49c9b48..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinLeavesBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.LeavesBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(LeavesBlock.class) -public class MixinLeavesBlock { - @Redirect(method = "updateDistanceFromLogs", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinPistonBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinPistonBlock.java deleted file mode 100644 index 21b1d88..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinPistonBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.PistonBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(PistonBlock.class) -public class MixinPistonBlock { - @Redirect(method = "shouldExtend", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneOreBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneOreBlock.java deleted file mode 100644 index bebee0e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneOreBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.RedstoneOreBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(RedstoneOreBlock.class) -public class MixinRedstoneOreBlock { - @Redirect(method = "spawnParticles", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneTorchBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneTorchBlock.java deleted file mode 100644 index 312a7ba..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneTorchBlock.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.RedstoneTorchBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(RedstoneTorchBlock.class) -public class MixinRedstoneTorchBlock { - @Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "onStateReplaced", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneWireBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneWireBlock.java deleted file mode 100644 index 21c216b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinRedstoneWireBlock.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.RedstoneWireBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(RedstoneWireBlock.class) -public class MixinRedstoneWireBlock { - @Redirect(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "updateNeighbors", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "onStateReplaced", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values3() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinSpongeBlock.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinSpongeBlock.java deleted file mode 100644 index 416c6f9..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/MixinSpongeBlock.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block; - -import net.minecraft.block.SpongeBlock; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(SpongeBlock.class) -public class MixinSpongeBlock { - @Redirect(method = "absorbWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/entity/MixinEndGatewayBlockEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/entity/MixinEndGatewayBlockEntity.java deleted file mode 100644 index f2fc8ed..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/entity/MixinEndGatewayBlockEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block.entity; - -import net.minecraft.block.entity.EndGatewayBlockEntity; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(EndGatewayBlockEntity.class) -public class MixinEndGatewayBlockEntity { - @Redirect(method = "getDrawnSidesCount", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/pattern/MixinBlockPattern.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/pattern/MixinBlockPattern.java deleted file mode 100644 index 3ef2ccf..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/pattern/MixinBlockPattern.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block.pattern; - -import net.minecraft.block.pattern.BlockPattern; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BlockPattern.class) -public class MixinBlockPattern { - @Redirect(method = "searchAround", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/piston/MixinPistonHandler.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/piston/MixinPistonHandler.java deleted file mode 100644 index 5244ab0..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/block/piston/MixinPistonHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.block.piston; - -import net.minecraft.block.piston.PistonHandler; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(PistonHandler.class) -public class MixinPistonHandler { - @Redirect(method = "canMoveAdjacentBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinAmphibiousPathNodeMarker.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinAmphibiousPathNodeMarker.java deleted file mode 100644 index 635c583..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinAmphibiousPathNodeMarker.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.entity.ai.pathing; - -import net.minecraft.entity.ai.pathing.AmphibiousPathNodeMaker; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(AmphibiousPathNodeMaker.class) -public class MixinAmphibiousPathNodeMarker { - @Redirect(method = "getDefaultNodeType", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinWaterPathNodeMarker.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinWaterPathNodeMarker.java deleted file mode 100644 index bdee97b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/ai/pathing/MixinWaterPathNodeMarker.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.entity.ai.pathing; - -import net.minecraft.entity.ai.pathing.WaterPathNodeMaker; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(WaterPathNodeMaker.class) -public class MixinWaterPathNodeMarker { - @Redirect(method = "getSuccessors", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/mob/MixinShulkerEntity.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/mob/MixinShulkerEntity.java deleted file mode 100644 index fc842cf..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/entity/mob/MixinShulkerEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.entity.mob; - -import net.minecraft.entity.mob.ShulkerEntity; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ShulkerEntity.class) -public class MixinShulkerEntity { - @Redirect(method = "findAttachSide", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/fluid/MixinLavaFluid.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/fluid/MixinLavaFluid.java deleted file mode 100644 index 8ad96de..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/fluid/MixinLavaFluid.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.fluid; - -import net.minecraft.fluid.LavaFluid; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(LavaFluid.class) -public class MixinLavaFluid { - @Redirect(method = "canLightFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/math/MixinDirectionTransformation.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/math/MixinDirectionTransformation.java deleted file mode 100644 index d608915..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/math/MixinDirectionTransformation.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.math; - -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.DirectionTransformation; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(DirectionTransformation.class) -public class MixinDirectionTransformation { - @Redirect(method = "map", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/property/MixinDirectionProperty.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/property/MixinDirectionProperty.java deleted file mode 100644 index 70c8451..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/property/MixinDirectionProperty.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.property; - -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(DirectionProperty.class) -public class MixinDirectionProperty { - @Redirect(method = "of(Ljava/lang/String;Ljava/util/function/Predicate;)Lnet/minecraft/state/property/DirectionProperty;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/block/MixinBlockModelRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/block/MixinBlockModelRenderer.java deleted file mode 100644 index 9260911..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/block/MixinBlockModelRenderer.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.block; - -import net.minecraft.client.render.block.BlockModelRenderer; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BlockModelRenderer.class) -public class MixinBlockModelRenderer { - @Redirect(method = "renderSmooth", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "renderFlat", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "getQuadDimensions", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values3() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "render(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/block/BlockState;Lnet/minecraft/client/render/model/BakedModel;FFFII)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values4() { - return PerformanceUtil.getDirectionArray(); - } - - @Mixin(BlockModelRenderer.NeighborOrientation.class) - public static class MixinNeighborOrientation { - - @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinBuiltChunk.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinBuiltChunk.java deleted file mode 100644 index d6902fc..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinBuiltChunk.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.chunk; - -import net.minecraft.client.render.chunk.ChunkBuilder; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ChunkBuilder.BuiltChunk.class) -public class MixinBuiltChunk { - @Redirect(method = "setOrigin", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinChunkOcclusionData.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinChunkOcclusionData.java deleted file mode 100644 index a2ace30..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/chunk/MixinChunkOcclusionData.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.chunk; - -import net.minecraft.client.render.chunk.ChunkOcclusionData; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ChunkOcclusionData.class) -public class MixinChunkOcclusionData { - @Redirect(method = "toString", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/item/MixinItemRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/item/MixinItemRenderer.java deleted file mode 100644 index a2b58e7..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/item/MixinItemRenderer.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.item; - -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ItemRenderer.class) -public class MixinItemRenderer { - @Redirect(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBakedQuadFactory.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBakedQuadFactory.java deleted file mode 100644 index 52dd18e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBakedQuadFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.model; - -import net.minecraft.client.render.model.BakedQuadFactory; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BakedQuadFactory.class) -public class MixinBakedQuadFactory { - @Redirect(method = "decodeDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "getPositionMatrix", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "encodeDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values3() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBasicBakedModelBuilder.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBasicBakedModelBuilder.java deleted file mode 100644 index 9218ebd..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/render/model/MixinBasicBakedModelBuilder.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.render.model; - -import net.minecraft.client.render.model.BasicBakedModel; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BasicBakedModel.Builder.class) -public class MixinBasicBakedModelBuilder { - @Redirect(method = "(ZZZLnet/minecraft/client/render/model/json/ModelTransformation;Lnet/minecraft/client/render/model/json/ModelOverrideList;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinBuriedTreasureGeneratorPiece.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinBuriedTreasureGeneratorPiece.java deleted file mode 100644 index f7ffe67..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinBuriedTreasureGeneratorPiece.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.structure; - -import net.minecraft.structure.BuriedTreasureGenerator; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BuriedTreasureGenerator.Piece.class) -public class MixinBuriedTreasureGeneratorPiece { - @Redirect(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinOceanMonumentGeneratorBase.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinOceanMonumentGeneratorBase.java deleted file mode 100644 index 391d71a..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/structure/MixinOceanMonumentGeneratorBase.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.structure; - -import net.minecraft.structure.OceanMonumentGenerator; -import net.minecraft.util.math.Direction; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(OceanMonumentGenerator.Base.class) -public class MixinOceanMonumentGeneratorBase { - @Redirect(method = "method_14760", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/chunk/MixinUpgradeData.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/chunk/MixinUpgradeData.java deleted file mode 100644 index 5b15103..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/chunk/MixinUpgradeData.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.world.chunk; - -import net.minecraft.util.math.Direction; -import net.minecraft.world.chunk.UpgradeData; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(UpgradeData.class) -public class MixinUpgradeData { - @Redirect(method = "upgradeSide", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private static Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } - - @Redirect(method = "upgradeCenter", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values2() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinBlueIceFeature.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinBlueIceFeature.java deleted file mode 100644 index 10e67c3..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinBlueIceFeature.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.world.gen.feature; - -import net.minecraft.util.math.Direction; -import net.minecraft.world.gen.feature.BlueIceFeature; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BlueIceFeature.class) -public class MixinBlueIceFeature { - @Redirect(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinGlowstoneBlobFeature.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinGlowstoneBlobFeature.java deleted file mode 100644 index f2f39ce..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinGlowstoneBlobFeature.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.world.gen.feature; - -import net.minecraft.util.math.Direction; -import net.minecraft.world.gen.feature.GlowstoneBlobFeature; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(GlowstoneBlobFeature.class) -public class MixinGlowstoneBlobFeature { - @Redirect(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinNoSurfaceOreFeature.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinNoSurfaceOreFeature.java deleted file mode 100644 index 2ec1a5e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinNoSurfaceOreFeature.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.world.gen.feature; - -import net.minecraft.util.math.Direction; -import net.minecraft.world.gen.feature.NoSurfaceOreFeature; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(NoSurfaceOreFeature.class) -public class MixinNoSurfaceOreFeature { - @Redirect(method = "checkAir", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinTreeFeature.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinTreeFeature.java deleted file mode 100644 index 196a1f5..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/direction_values/world/gen/feature/MixinTreeFeature.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.direction_values.world.gen.feature; - -import net.minecraft.util.math.Direction; -import net.minecraft.world.gen.feature.TreeFeature; -import org.sandboxpowered.sandbox.fabric.util.PerformanceUtil; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(TreeFeature.class) -public class MixinTreeFeature { - @Redirect(method = "placeLogsAndLeaves", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;values()[Lnet/minecraft/util/math/Direction;")) - private Direction[] values() { - return PerformanceUtil.getDirectionArray(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinClientWorld.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinClientWorld.java deleted file mode 100644 index 2e43671..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinClientWorld.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.particle_culling; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.particle.ParticleEffect; -import net.minecraft.util.math.Box; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.internal.IFrustumWorldRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ClientWorld.class) -public class MixinClientWorld { - - @Inject(method = "addParticle(Lnet/minecraft/particle/ParticleEffect;DDDDDD)V", at = @At(value = "HEAD"), cancellable = true) - private void addParticle(ParticleEffect particleEffect, double d, double e, double f, double g, double h, double i, CallbackInfo info) { - cullUnimportantParticles(particleEffect, false, d, e, f, info); - } - - @Inject(method = "addParticle(Lnet/minecraft/particle/ParticleEffect;ZDDDDDD)V", at = @At(value = "HEAD"), cancellable = true) - private void addParticle(ParticleEffect particleEffect, boolean bl, double d, double e, double f, double g, double h, double i, CallbackInfo info) { - cullUnimportantParticles(particleEffect, bl, d, e, f, info); - } - - private void cullUnimportantParticles(ParticleEffect particleEffect, boolean bl, double d, double e, double f, CallbackInfo info) { - if (SandboxConfig.cullParticles.getBoolean()) { - boolean shouldSpawn = particleEffect.getType().shouldAlwaysSpawn() || bl; - if (!shouldSpawn && !((IFrustumWorldRenderer) MinecraftClient.getInstance().worldRenderer).sandboxGetFrustum().isVisible(new Box(d, e, f, d + 0.25f, e + 0.25f, f + 0.25f))) { - info.cancel(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinParticleManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinParticleManager.java deleted file mode 100644 index 547864f..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinParticleManager.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.particle_culling; - -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleManager; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.Frustum; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.internal.IFrustumWorldRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(ParticleManager.class) -public class MixinParticleManager { - @Redirect(method = "renderParticles", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/particle/Particle;buildGeometry(Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/client/render/Camera;F)V")) - private void cullParticles(Particle particle, VertexConsumer consumer, Camera camera, float partialTicks) { - if (SandboxConfig.cullParticles.getBoolean()) { - if (((IFrustumWorldRenderer) MinecraftClient.getInstance().worldRenderer).sandboxGetFrustum().isVisible(particle.getBoundingBox())) { - particle.buildGeometry(consumer, camera, partialTicks); - } - } else { - particle.buildGeometry(consumer, camera, partialTicks); - } - } - - @Inject(locals = LocalCapture.CAPTURE_FAILHARD, - method = "addBlockBreakingParticles", - at = @At(value = "INVOKE", target = "Lnet/minecraft/util/shape/VoxelShape;getBoundingBox()Lnet/minecraft/util/math/Box;", shift = At.Shift.BY, by = 2), - cancellable = true - ) - private void addBlockBreakingParticles(BlockPos blockPos, Direction direction, CallbackInfo ci, BlockState state, int i, int j, int k, float f, Box box) { - if (SandboxConfig.cullParticles.getBoolean()) { - Frustum frustum = ((IFrustumWorldRenderer) MinecraftClient.getInstance().worldRenderer).sandboxGetFrustum(); - if (frustum != null && frustum.isVisible(box.offset(blockPos))) { - ci.cancel(); - } - } - } - - @Inject(locals = LocalCapture.CAPTURE_FAILHARD, - method = "addBlockBreakParticles", - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getOutlineShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/shape/VoxelShape;", shift = At.Shift.BY, by = 2), - cancellable = true - ) - private void addBlockBreakParticles(BlockPos blockPos, BlockState state, CallbackInfo ci, VoxelShape shape) { - if (SandboxConfig.cullParticles.getBoolean()) { - Frustum frustum = ((IFrustumWorldRenderer) MinecraftClient.getInstance().worldRenderer).sandboxGetFrustum(); - if (frustum != null && shape.getBoundingBoxes().stream().map(box -> box.offset(blockPos)).noneMatch(frustum::isVisible)) { - ci.cancel(); - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinWorldRenderer.java b/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinWorldRenderer.java deleted file mode 100644 index 8597f41..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/mixin/performance/particle_culling/MixinWorldRenderer.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.mixin.performance.particle_culling; - -import net.minecraft.client.render.*; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.Matrix4f; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.profiler.Profiler; -import org.sandboxpowered.sandbox.fabric.internal.IFrustumWorldRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(WorldRenderer.class) -public class MixinWorldRenderer implements IFrustumWorldRenderer { - - private Frustum sandboxFrustum; - - @Inject(locals = LocalCapture.CAPTURE_FAILHARD, - method = "render", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BackgroundRenderer;render(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/world/ClientWorld;IF)V") - ) - private void captureFrustum(MatrixStack stack, float f, long l, boolean b, Camera camera, GameRenderer renderer, LightmapTextureManager lightmap, Matrix4f matrix, CallbackInfo ci, Profiler iprofiler, Vec3d vec3d, double d0, double d1, double d2, Matrix4f matrix4f, boolean flag, Frustum capturedFustrum) { - if (capturedFustrum != null) - this.sandboxFrustum = capturedFustrum; - } - - @Override - public Frustum sandboxGetFrustum() { - return this.sandboxFrustum; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/network/AddonS2CPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/network/AddonS2CPacket.java deleted file mode 100644 index 4405cc1..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/network/AddonS2CPacket.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.network; - -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Pair; -import org.sandboxpowered.sandbox.fabric.Sandbox; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class AddonS2CPacket implements Packet { - private int count; - private String prefix; - private List> addons; - - public AddonS2CPacket(int count, String prefix, List> addons) { - this.count = count; - this.prefix = prefix; - this.addons = addons; - } - - public AddonS2CPacket() { - } - - @Override - public void read(PacketByteBuf var1) { - count = var1.readInt(); - prefix = var1.readString(Short.MAX_VALUE); - if (count > 0) { - addons = new ArrayList<>(); - } else { - addons = Collections.emptyList(); - } - for (int i = 0; i < count; i++) { - String suffix = var1.readString(Short.MAX_VALUE); - String hash = var1.readString(Short.MAX_VALUE); - addons.add(new Pair<>(suffix, hash)); - } - } - - @Override - public void write(PacketByteBuf var1) { - var1.writeInt(count); - var1.writeString(prefix); - addons.forEach(pair -> { - var1.writeString(pair.getLeft(), Short.MAX_VALUE); - var1.writeString(pair.getRight(), Short.MAX_VALUE); - }); - } - - @Override - public void apply() { - Sandbox.open(prefix, addons); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/network/ContainerOpenPacket.java b/src/main/java/org/sandboxpowered/sandbox/fabric/network/ContainerOpenPacket.java deleted file mode 100644 index 94d760c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/network/ContainerOpenPacket.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.network; - -import net.minecraft.network.PacketByteBuf; -import org.sandboxpowered.api.util.Identity; -import org.sandboxpowered.api.util.nbt.CompoundTag; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -public class ContainerOpenPacket implements Packet { - private Identity id; - private int syncId; - private CompoundTag data; - - public ContainerOpenPacket(Identity id, int syncId, CompoundTag data) { - this.id = id; - this.syncId = syncId; - this.data = data; - } - - public ContainerOpenPacket() { - } - - @Override - public void read(PacketByteBuf buf) { - id = (Identity) buf.readIdentifier(); - syncId = buf.readInt(); - data = (CompoundTag) buf.readCompoundTag(); - } - - @Override - public void write(PacketByteBuf buf) { - buf.writeIdentifier(WrappingUtil.convert(id)); - buf.writeInt(syncId); - buf.writeCompoundTag((net.minecraft.nbt.CompoundTag) data); - } - - @Override - public void apply() { -// MinecraftClient.getInstance().execute(() -> { -// Registries.CONTAINER.get(id).ifPresent(factory -> { -// Container container = factory.create(id, new V2SInventory(MinecraftClient.getInstance().player.inventory), data); -// if (container != null) { -// ContainerScreen screen = factory.create(container); -// MinecraftClient.getInstance().player.container = new ContainerWrapper(null, syncId, container); -// MinecraftClient.getInstance().openScreen(WrappingUtil.convert(screen)); -// } -// }, () -> Log.error("No Container factory found for " + id.toString() + "!")); -// }); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/network/NetworkManager.java b/src/main/java/org/sandboxpowered/sandbox/fabric/network/NetworkManager.java deleted file mode 100644 index 8c98349..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/network/NetworkManager.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.network; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import io.netty.buffer.Unpooled; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.Sandbox; - -import java.util.Objects; - -public class NetworkManager { - - private static final BiMap> packetMap = HashBiMap.create(); - private static final BiMap, Identifier> packetMapInverse = packetMap.inverse(); - - static { - add(new Identifier(Sandbox.ID, "addon_sync"), AddonS2CPacket.class); - add(new Identifier(Sandbox.ID, "container_open"), ContainerOpenPacket.class); - } - - public static void add(Identifier id, Class packetClass) { - packetMap.put(id, packetClass); - } - - public static Class get(Identifier id) { - return packetMap.get(id); - } - - public static void sendToServer(Packet packet) { - Identifier id = getId(packet); - Objects.requireNonNull(MinecraftClient.getInstance().getNetworkHandler()).sendPacket(c2s(id, packet)); - } - - public static void sendTo(Packet packet, PlayerEntity player) { - if (player instanceof ServerPlayerEntity) - sendTo(packet, (ServerPlayerEntity) player); - } - - public static void sendTo(Packet packet, ServerPlayerEntity player) { - Identifier id = getId(packet); - player.networkHandler.sendPacket(s2c(id, packet)); - } - - private static Identifier getId(Packet packet) { - return packetMapInverse.get(packet.getClass()); - } - - private static CustomPayloadC2SPacket c2s(Identifier id, Packet packet) { - PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); - packet.write(buf); - return new CustomPayloadC2SPacket(id, buf); - } - - private static CustomPayloadS2CPacket s2c(Identifier id, Packet packet) { - PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); - packet.write(buf); - return new CustomPayloadS2CPacket(id, buf); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/network/Packet.java b/src/main/java/org/sandboxpowered/sandbox/fabric/network/Packet.java deleted file mode 100644 index bcfaa7c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/network/Packet.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.network; - -import net.minecraft.network.PacketByteBuf; - -public interface Packet { - void read(PacketByteBuf buf); - - void write(PacketByteBuf buf); - - void apply(); -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/resources/SandboxResourceCreator.java b/src/main/java/org/sandboxpowered/sandbox/fabric/resources/SandboxResourceCreator.java deleted file mode 100644 index dfade04..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/resources/SandboxResourceCreator.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.resources; - -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.resource.ResourcePackProfile; -import net.minecraft.resource.ResourcePackProvider; -import net.minecraft.resource.ResourcePackSource; -import org.sandboxpowered.sandbox.fabric.Sandbox; -import org.sandboxpowered.sandbox.fabric.SandboxResources; - -import java.util.function.Consumer; - -public class SandboxResourceCreator implements ResourcePackProvider { - @Override - public void register(Consumer consumer, ResourcePackProfile.Factory factory) { - FabricLoader.getInstance().getModContainer(Sandbox.ID).map(modContainer -> ResourcePackProfile.of( - "Sandbox Resources", - true, - () -> new SandboxResources(modContainer.getRootPath()), - factory, - ResourcePackProfile.InsertionPosition.BOTTOM, - ResourcePackSource.PACK_SOURCE_BUILTIN - )).ifPresent(consumer); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonClassLoader.java b/src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonClassLoader.java deleted file mode 100644 index 1967293..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/security/AddonClassLoader.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.security; - -import org.sandboxpowered.internal.AddonSpec; - -import java.io.FilePermission; -import java.net.URL; -import java.net.URLClassLoader; -import java.security.CodeSource; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.SecureClassLoader; - -public class AddonClassLoader extends SecureClassLoader { - static { - registerAsParallelCapable(); - } - - private final AddonSpec spec; - private final DynamicURLClassLoader classLoader = (DynamicURLClassLoader) getParent(); - - public AddonClassLoader(ClassLoader original, AddonSpec spec) { - super(new DynamicURLClassLoader(new URL[0], original)); - this.spec = spec; - } - - public void addURL(URL url) { - classLoader.addURL(url); - } - - @Override - protected PermissionCollection getPermissions(CodeSource codesource) { - Permissions pc = new Permissions(); - pc.add(new FilePermission("data/-", "read")); // Can read everything from data dir - pc.add(new FilePermission(String.format("data/%s/-", spec.getId()), "read,write,delete")); // Can write everything inside addon data dir - return pc; - } - - private static class DynamicURLClassLoader extends URLClassLoader { - static { - registerAsParallelCapable(); - } - - private DynamicURLClassLoader(URL[] urls, ClassLoader original) { - super(urls, original); - } - - @Override - public void addURL(URL url) { - super.addURL(url); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/AddonLog.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/AddonLog.java deleted file mode 100644 index e4ed010..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/AddonLog.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.sandboxpowered.api.addon.AddonInfo; -import org.sandboxpowered.api.util.Log; - -public class AddonLog implements Log { - private final AddonInfo info; - private final Logger logger; - - public AddonLog(AddonInfo info) { - this.info = info; - logger = LogManager.getFormatterLogger(info.getTitle()); - } - - @Override - public void info(String message) { - logger.info(message); - } - - @Override - public void error(String message) { - logger.error(message); - } - - @Override - public void debug(String message) { - logger.debug(message); - } - - public AddonInfo getInfo() { - return info; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/ArrayUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/ArrayUtil.java deleted file mode 100644 index 04829c8..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/ArrayUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import org.apache.commons.lang3.ArrayUtils; - -public class ArrayUtil { - private ArrayUtil() { - } - - @SafeVarargs - public static T[] removeAll(T[] arr, T... occ) { - for (T oc : occ) { - arr = ArrayUtils.removeAllOccurences(arr, oc); - } - return arr; - } - - public static String join(String[] filenames, String s) { - if (filenames.length == 1) - return filenames[0]; - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < filenames.length; i++) { - String filename = filenames[i]; - builder.append(filename); - if (i != filenames.length - 1) - builder.append(s); - } - return builder.toString(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/Log.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/Log.java deleted file mode 100644 index a5e0a88..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/Log.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class Log { - public static final Logger LOGGER = LogManager.getFormatterLogger("Sandbox|Fabric"); - - private Log() { - } - - public static void info(String message) { - LOGGER.info(message); - } - - public static void info(String message, Object... objs) { - LOGGER.info(message, objs); - } - - public static void error(String message) { - LOGGER.error(message); - } - - public static void error(String message, Throwable e) { - LOGGER.error(message, e); - } - - public static void error(String message, Object... objs) { - LOGGER.error(message, objs); - } - - public static void warn(String message) { - LOGGER.warn(message); - } - - public static void warn(String message, Throwable e) { - LOGGER.warn(message, e); - } - - public static void warn(String message, Object... objs) { - LOGGER.warn(message, objs); - } - - public static void fatal(String message) { - LOGGER.fatal(message); - } - - public static void fatal(String message, Throwable e) { - LOGGER.fatal(message, e); - } - - public static void fatal(String message, Object... objs) { - LOGGER.fatal(message, objs); - } - - public static void debug(String message) { - LOGGER.info(message); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/MaterialUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/MaterialUtil.java deleted file mode 100644 index 4b175e3..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/MaterialUtil.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import org.sandboxpowered.api.block.Material; - -public class MaterialUtil { - private MaterialUtil() { - } - - @SuppressWarnings("java:S1479") - public static Material from(String s) { - switch (s) { - case "AIR": - return WrappingUtil.cast(net.minecraft.block.Material.AIR, Material.class); - case "ANVIL": - case "REPAIR_STATION": - return WrappingUtil.cast(net.minecraft.block.Material.REPAIR_STATION, Material.class); - case "METAL": - return WrappingUtil.cast(net.minecraft.block.Material.METAL, Material.class); - case "BAMBOO": - return WrappingUtil.cast(net.minecraft.block.Material.BAMBOO, Material.class); - case "BAMBOO_SAPLING": - return WrappingUtil.cast(net.minecraft.block.Material.BAMBOO_SAPLING, Material.class); - case "BARRIER": - return WrappingUtil.cast(net.minecraft.block.Material.BARRIER, Material.class); - case "BUBBLE_COLUMN": - return WrappingUtil.cast(net.minecraft.block.Material.BUBBLE_COLUMN, Material.class); - case "STONE": - return WrappingUtil.cast(net.minecraft.block.Material.STONE, Material.class); - case "LAVA": - return WrappingUtil.cast(net.minecraft.block.Material.LAVA, Material.class); - case "WATER": - return WrappingUtil.cast(net.minecraft.block.Material.WATER, Material.class); - case "UNDERWATER_PLANT": - return WrappingUtil.cast(net.minecraft.block.Material.UNDERWATER_PLANT, Material.class); - case "CACTUS": - return WrappingUtil.cast(net.minecraft.block.Material.CACTUS, Material.class); - case "CAKE": - return WrappingUtil.cast(net.minecraft.block.Material.CAKE, Material.class); - case "CARPET": - return WrappingUtil.cast(net.minecraft.block.Material.CARPET, Material.class); - case "CLAY": - case "ORGANIC_PRODUCT": - return WrappingUtil.cast(net.minecraft.block.Material.ORGANIC_PRODUCT, Material.class); - case "PISTON": - return WrappingUtil.cast(net.minecraft.block.Material.PISTON, Material.class); - case "UNUSED_PLANT": - return WrappingUtil.cast(net.minecraft.block.Material.UNUSED_PLANT, Material.class); - case "TNT": - return WrappingUtil.cast(net.minecraft.block.Material.TNT, Material.class); - case "STRUCTURE_VOID": - return WrappingUtil.cast(net.minecraft.block.Material.STRUCTURE_VOID, Material.class); - case "SNOW": - case "SNOW_LAYER": - return WrappingUtil.cast(net.minecraft.block.Material.SNOW_LAYER, Material.class); - case "SNOW_BLOCK": - return WrappingUtil.cast(net.minecraft.block.Material.SNOW_BLOCK, Material.class); - case "COBWEB": - return WrappingUtil.cast(net.minecraft.block.Material.COBWEB, Material.class); - case "FIRE": - return WrappingUtil.cast(net.minecraft.block.Material.FIRE, Material.class); - case "SHULKER_BOX": - return WrappingUtil.cast(net.minecraft.block.Material.SHULKER_BOX, Material.class); - case "AGGREGATE": - case "SAND": - return WrappingUtil.cast(net.minecraft.block.Material.AGGREGATE, Material.class); - case "ORGANIC": - return WrappingUtil.cast(net.minecraft.block.Material.ORGANIC_PRODUCT, Material.class); - case "PORTAL": - return WrappingUtil.cast(net.minecraft.block.Material.PORTAL, Material.class); - case "REPLACEABLE_PLANT": - return WrappingUtil.cast(net.minecraft.block.Material.REPLACEABLE_PLANT, Material.class); - case "PLANT": - return WrappingUtil.cast(net.minecraft.block.Material.PLANT, Material.class); - case "PUMPKIN": - case "GOURD": - return WrappingUtil.cast(net.minecraft.block.Material.GOURD, Material.class); - case "SEAGRASS": - case "REPLACEABLE_UNDERWATER_PLANT": - return WrappingUtil.cast(net.minecraft.block.Material.REPLACEABLE_UNDERWATER_PLANT, Material.class); - case "SUPPORTED": - case "PART": - return WrappingUtil.cast(net.minecraft.block.Material.SUPPORTED, Material.class); - case "DENSE_ICE": - case "PACKED_ICE": - return WrappingUtil.cast(net.minecraft.block.Material.DENSE_ICE, Material.class); - case "EGG": - return WrappingUtil.cast(net.minecraft.block.Material.EGG, Material.class); - case "ICE": - return WrappingUtil.cast(net.minecraft.block.Material.ICE, Material.class); - case "EARTH": - case "SOIL": - return WrappingUtil.cast(net.minecraft.block.Material.SOIL, Material.class); - case "REDSTONE_LAMP": - return WrappingUtil.cast(net.minecraft.block.Material.REDSTONE_LAMP, Material.class); - case "SPONGE": - return WrappingUtil.cast(net.minecraft.block.Material.SPONGE, Material.class); - case "WOOD": - return WrappingUtil.cast(net.minecraft.block.Material.WOOD, Material.class); - case "WOOL": - return WrappingUtil.cast(net.minecraft.block.Material.WOOL, Material.class); - case "LEAVES": - return WrappingUtil.cast(net.minecraft.block.Material.LEAVES, Material.class); - case "GLASS": - return WrappingUtil.cast(net.minecraft.block.Material.GLASS, Material.class); - default: - throw new RuntimeException("Unknown Material " + s); - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/PerformanceUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/PerformanceUtil.java deleted file mode 100644 index 6eb55c3..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/PerformanceUtil.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import net.minecraft.util.math.Direction; - -public class PerformanceUtil { - private static final Direction[] DIRECTIONS = Direction.values(); - - private PerformanceUtil() { - } - - public static Direction[] getDirectionArray() { - return DIRECTIONS; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/PropertyUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/PropertyUtil.java deleted file mode 100644 index 05fcd3e..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/PropertyUtil.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import net.minecraft.state.property.Properties; -import org.sandboxpowered.api.state.Property; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.api.util.SlabType; -import org.sandboxpowered.sandbox.fabric.util.wrapper.EnumPropertyWrapper; - -public class PropertyUtil { - public static final EnumPropertyWrapper FACING = new EnumPropertyWrapper<>( - Properties.FACING, - WrappingUtil::convert, - WrappingUtil::convert, - Direction.class - ); - public static final EnumPropertyWrapper HORIZONTAL = new EnumPropertyWrapper<>( - Properties.HORIZONTAL_FACING, - WrappingUtil::convert, - WrappingUtil::convert, - Direction.class - ); - public static final EnumPropertyWrapper HOPPER_FACING = new EnumPropertyWrapper<>( - Properties.HOPPER_FACING, - WrappingUtil::convert, - WrappingUtil::convert, - Direction.class - ); - public static final EnumPropertyWrapper AXIS = new EnumPropertyWrapper<>( - Properties.AXIS, - WrappingUtil::convert, - WrappingUtil::convert, - Direction.Axis.class - ); - public static final EnumPropertyWrapper HORIZONTAL_AXIS = new EnumPropertyWrapper<>( - Properties.HORIZONTAL_AXIS, - WrappingUtil::convert, - WrappingUtil::convert, - Direction.Axis.class - ); - public static final EnumPropertyWrapper SLAB_TYPE = new EnumPropertyWrapper<>( - Properties.SLAB_TYPE, - WrappingUtil::convert, - WrappingUtil::convert, - SlabType.class - ); - private PropertyUtil() { - } - - @SuppressWarnings("unchecked") - public static > Property get(String s) { - switch (s) { - case "attached": - return (Property) Properties.ATTACHED; - case "bottom": - return (Property) Properties.BOTTOM; - case "conditional": - return (Property) Properties.CONDITIONAL; - case "disarmed": - return (Property) Properties.DISARMED; - case "drag": - return (Property) Properties.DRAG; - case "enabled": - return (Property) Properties.ENABLED; - case "extended": - return (Property) Properties.EXTENDED; - case "eye": - return (Property) Properties.EYE; - case "falling": - return (Property) Properties.FALLING; - case "hanging": - return (Property) Properties.HANGING; - case "has_bottle_0": - return (Property) Properties.HAS_BOTTLE_0; - case "has_bottle_1": - return (Property) Properties.HAS_BOTTLE_1; - case "has_bottle_2": - return (Property) Properties.HAS_BOTTLE_2; - case "has_record": - return (Property) Properties.HAS_RECORD; - case "has_book": - return (Property) Properties.HAS_BOOK; - case "inverted": - return (Property) Properties.INVERTED; - case "in_wall": - return (Property) Properties.IN_WALL; - case "lit": - return (Property) Properties.LIT; - case "locked": - return (Property) Properties.LOCKED; - case "occupied": - return (Property) Properties.OCCUPIED; - case "open": - return (Property) Properties.OPEN; - case "persistent": - return (Property) Properties.PERSISTENT; - case "powered": - return (Property) Properties.POWERED; - case "short": - return (Property) Properties.SHORT; - case "signal_fire": - return (Property) Properties.SIGNAL_FIRE; - case "snowy": - return (Property) Properties.SNOWY; - case "triggered": - return (Property) Properties.TRIGGERED; - case "unstable": - return (Property) Properties.UNSTABLE; - case "waterlogged": - return (Property) Properties.WATERLOGGED; - case "fluidlevel": - return (Property) Properties.LEVEL_1_8; - case "level_15": - return (Property) Properties.LEVEL_15; - case "up": - return (Property) Properties.UP; - case "down": - return (Property) Properties.DOWN; - case "east": - return (Property) Properties.EAST; - case "west": - return (Property) Properties.WEST; - case "north": - return (Property) Properties.NORTH; - case "south": - return (Property) Properties.SOUTH; - case "age_1": - return (Property) Properties.AGE_1; - case "age_2": - return (Property) Properties.AGE_2; - case "age_3": - return (Property) Properties.AGE_3; - case "age_5": - return (Property) Properties.AGE_5; - case "age_7": - return (Property) Properties.AGE_7; - case "age_15": - return (Property) Properties.AGE_15; - case "age_25": - return (Property) Properties.AGE_25; - case "bites": - return (Property) Properties.BITES; - case "delay": - return (Property) Properties.DELAY; - case "distance_1_7": - return (Property) Properties.DISTANCE_1_7; - case "eggs": - return (Property) Properties.EGGS; - case "hatch": - return (Property) Properties.HATCH; - case "layers": - return (Property) Properties.LAYERS; - case "level_3": - return (Property) Properties.LEVEL_3; - case "level_8": - return (Property) Properties.LEVEL_8; - case "level_1_8": - return (Property) Properties.LEVEL_1_8; - case "honey_level": - return (Property) Properties.HONEY_LEVEL; - case "moisture": - return (Property) Properties.MOISTURE; - case "note": - return (Property) Properties.NOTE; - case "pickles": - return (Property) Properties.PICKLES; - case "power": - return (Property) Properties.POWER; - case "stage": - return (Property) Properties.STAGE; - case "distance_0_7": - return (Property) Properties.DISTANCE_0_7; - case "rotation": - return (Property) Properties.ROTATION; - case "facing": - return (Property) FACING; - case "horizontal_facing": - return (Property) HORIZONTAL; - case "hopper_facing": - return (Property) HOPPER_FACING; - case "axis": - return (Property) AXIS; - case "horizontal_axis": - return (Property) HORIZONTAL_AXIS; - case "slab_type": - return (Property) SLAB_TYPE; - default: - return null; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/ReflectionHelper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/ReflectionHelper.java deleted file mode 100644 index cb5fd6b..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/ReflectionHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Arrays; - -public class ReflectionHelper { - private static Field mods; - - private ReflectionHelper() { - } - - public static void setPrivateField(Class c, A obj, String[] fields, Object val) throws NoSuchFieldException, IllegalAccessException { - boolean done = false; - for (String field : fields) { - try { - setPrivateField(c, obj, field, val); - done = true; - break; - } catch (NoSuchFieldException ignored) { - } - } - if (!done) - throw new NoSuchFieldException(Arrays.toString(fields)); - } - - @SuppressWarnings("java:S3011") - public static void setPrivateField(Class c, A obj, String field, Object val) throws NoSuchFieldException, IllegalAccessException { - Field m = c.getDeclaredField(field); - m.setAccessible(true); - if (Modifier.isFinal(m.getModifiers())) - getMods().setInt(m, m.getModifiers() & ~Modifier.FINAL); - m.set(obj, val); - } - - @SuppressWarnings("java:S3011") - private static Field getMods() throws NoSuchFieldException { - if (mods == null) { - mods = Field.class.getDeclaredField("modifiers"); - mods.setAccessible(true); - } - return mods; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/RegistryUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/RegistryUtil.java deleted file mode 100644 index 4101344..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/RegistryUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import net.minecraft.block.Block; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.util.ModelIdentifier; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.util.registry.Registry; -import org.sandboxpowered.sandbox.fabric.Sandbox; - -public class RegistryUtil { - private RegistryUtil() { - } - - public static void doOnSet(Object object) { - if (object instanceof Item && Sandbox.SANDBOX.getSide().isClient()) { - MinecraftClient.getInstance().getItemRenderer().getModels().putModel((Item) object, new ModelIdentifier(Registry.ITEM.getId((Item) object), "inventory")); - } - if (object instanceof BlockItem) { - ((BlockItem) object).appendBlocks(Item.BLOCK_ITEMS, (BlockItem) object); - } - if (object instanceof Block) { - ((Block) object).getStateManager().getStates().forEach(Block.STATE_IDS::add); - //TODO: Also need to reset the state ids - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/SameBlockContext.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/SameBlockContext.java deleted file mode 100644 index 7c6f330..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/SameBlockContext.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class SameBlockContext extends ItemPlacementContext { - public SameBlockContext(ItemUsageContext context) { - super(context); - this.canReplaceExisting = true; - } - - public SameBlockContext(World world, @Nullable PlayerEntity player, Hand hand, ItemStack stack, BlockHitResult hitResult) { - super(world, player, hand, stack, hitResult); - this.canReplaceExisting = true; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/SandboxStorage.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/SandboxStorage.java deleted file mode 100644 index e4ecaf9..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/SandboxStorage.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import org.sandboxpowered.api.client.Client; -import org.sandboxpowered.api.server.Server; - -public class SandboxStorage { - private static Client client; - private static Server server; - - private SandboxStorage() { - } - - public static Client getClient() { - return client; - } - - public static void setClient(Client client) { - SandboxStorage.client = client; - } - - public static Server getServer() { - return server; - } - - public static void setServer(Server server) { - SandboxStorage.server = server; - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/VelocityUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/VelocityUtil.java deleted file mode 100644 index 48f42f6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/VelocityUtil.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import com.google.common.net.InetAddresses; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import io.netty.buffer.Unpooled; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; -import net.minecraft.util.Identifier; -import org.sandboxpowered.sandbox.fabric.SandboxConfig; -import org.sandboxpowered.sandbox.fabric.internal.LoginQueryRequestPacket; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -import java.net.InetAddress; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class VelocityUtil { - public static final Identifier PLAYER_INFO_CHANNEL = new Identifier("velocity", "player_info"); - - private VelocityUtil() { - } - - public static boolean checkIntegrity(final PacketByteBuf buf) { - final byte[] signature = new byte[32]; - buf.readBytes(signature); - - final byte[] data = new byte[buf.readableBytes()]; - buf.getBytes(buf.readerIndex(), data); - - try { - final Mac mac = Mac.getInstance("HmacSHA256"); - mac.init(new SecretKeySpec(SandboxConfig.velocityKey.get().getBytes(), "HmacSHA256")); - final byte[] mySignature = mac.doFinal(data); - if (!MessageDigest.isEqual(signature, mySignature)) { - return false; - } - } catch (final InvalidKeyException | NoSuchAlgorithmException e) { - throw new AssertionError(e); - } - - int version = buf.readVarInt(); - if (version != 1) { - throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted " + 1); - } - - return true; - } - - @SuppressWarnings("UnstableApiUsage") - public static InetAddress readAddress(final PacketByteBuf buf) { - return InetAddresses.forString(buf.readString(32767)); - } - - public static GameProfile createProfile(final PacketByteBuf buf) { - final GameProfile profile = new GameProfile(buf.readUuid(), buf.readString(16)); - readProperties(buf, profile); - return profile; - } - - private static void readProperties(final PacketByteBuf buf, final GameProfile profile) { - if (buf.readableBytes() < 4) - return; - final int properties = buf.readInt(); - for (int i1 = 0; i1 < properties; i1++) { - final String name = buf.readString(32767); - final String value = buf.readString(32767); - final String signature = buf.readBoolean() ? buf.readString(32767) : null; - profile.getProperties().put(name, new Property(name, value, signature)); - } - } - - public static LoginQueryRequestS2CPacket create(int id) { - LoginQueryRequestS2CPacket packet = new LoginQueryRequestS2CPacket(); - LoginQueryRequestPacket pack = (LoginQueryRequestPacket) packet; - pack.setQueryId(id); - pack.setChannel(PLAYER_INFO_CHANNEL); - pack.setPayload(new PacketByteBuf(Unpooled.buffer())); - return packet; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/WrappingUtil.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/WrappingUtil.java deleted file mode 100644 index 5470abd..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/WrappingUtil.java +++ /dev/null @@ -1,527 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util; - -import net.minecraft.block.AbstractBlock.Settings; -import net.minecraft.block.Material; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.piston.PistonBehavior; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.client.util.math.Vector3d; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.fluid.FluidState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.state.property.Property; -import net.minecraft.text.Text; -import net.minecraft.util.*; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.client.GraphicsMode; -import org.sandboxpowered.api.client.rendering.VertexConsumer; -import org.sandboxpowered.api.enchantment.Enchantment; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.entity.LivingEntity; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.fluid.BaseFluid; -import org.sandboxpowered.api.fluid.Fluid; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.shape.Box; -import org.sandboxpowered.api.shape.Shape; -import org.sandboxpowered.api.state.BlockState; -import org.sandboxpowered.api.util.*; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; -import org.sandboxpowered.api.world.BlockFlag; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.exception.WrappingException; -import org.sandboxpowered.sandbox.fabric.util.wrapper.*; - -import java.util.function.Function; - -@SuppressWarnings({"unchecked", "ConstantConditions"}) -public class WrappingUtil { - - private WrappingUtil() { - } - - public static BlockPos convert(Position position) { - return castOrWrap(position, BlockPos.class, p -> new BlockPosWrapper(position)); - } - - public static Position convert(BlockPos position) { - return cast(position, Position.class); - } - - public static net.minecraft.block.BlockState convert(BlockState state) { - return castOrWrap(state, net.minecraft.block.BlockState.class, s -> null); - } - - public static net.minecraft.block.Block convert(Block block) { - return castOrWrap(block, net.minecraft.block.Block.class, WrappingUtil::getWrapped); - } - - private static net.minecraft.block.Block getWrapped(Block block) { - if (block instanceof SandboxInternal.WrappedInjection) { - SandboxInternal.WrappedInjection wrappedInjection = (SandboxInternal.WrappedInjection) block; - if (wrappedInjection.getInjectionWrapped() == null) { - wrappedInjection.setInjectionWrapped(BlockWrapper.create(block)); - } - return (net.minecraft.block.Block) wrappedInjection.getInjectionWrapped(); - } - throw new WrappingException(block.getClass()); - } - - private static net.minecraft.item.Item getWrapped(Item item) { - if (item instanceof SandboxInternal.WrappedInjection) { - SandboxInternal.WrappedInjection wrappedInjection = (SandboxInternal.WrappedInjection) item; - if (wrappedInjection.getInjectionWrapped() == null) { - wrappedInjection.setInjectionWrapped(ItemWrapper.create(item)); - } - return (net.minecraft.item.Item) wrappedInjection.getInjectionWrapped(); - } - throw new WrappingException(item.getClass()); - } - - private static net.minecraft.enchantment.Enchantment getWrapped(Enchantment enchantment) { - if (enchantment instanceof SandboxInternal.WrappedInjection) { - SandboxInternal.WrappedInjection wrappedInjection = (SandboxInternal.WrappedInjection) enchantment; - if (wrappedInjection.getInjectionWrapped() == null) { - wrappedInjection.setInjectionWrapped(new EnchantmentWrapper(enchantment)); - } - return wrappedInjection.getInjectionWrapped(); - } - throw new WrappingException(enchantment.getClass()); - } - - private static net.minecraft.fluid.Fluid getWrapped(Fluid fluid) { - if (fluid instanceof BaseFluid && fluid instanceof SandboxInternal.WrappedInjection) { - SandboxInternal.WrappedInjection wrappedInjection = (SandboxInternal.WrappedInjection) fluid; - if (wrappedInjection.getInjectionWrapped() == null) { - wrappedInjection.setInjectionWrapped(FluidWrapper.create((BaseFluid) fluid)); - } - return wrappedInjection.getInjectionWrapped(); - } - throw new WrappingException(fluid.getClass()); - } - - public static net.minecraft.enchantment.Enchantment convert(Enchantment enchant) { - return castOrWrap(enchant, net.minecraft.enchantment.Enchantment.class, WrappingUtil::getWrapped); - } - - //Don't remove, used by the LambdaMetaFactory in the registries - public static Enchantment convert(net.minecraft.enchantment.Enchantment enchant) { - return (Enchantment) enchant; - } - - public static net.minecraft.block.Block[] convert(Block[] block) { - net.minecraft.block.Block[] arr = new net.minecraft.block.Block[block.length]; - for (int i = 0; i < block.length; i++) { - arr[i] = convert(block[i]); - } - return arr; - } - - public static net.minecraft.item.Item convert(Item item) { - return castOrWrap(item, net.minecraft.item.Item.class, WrappingUtil::getWrapped); - } - - public static Item convert(net.minecraft.item.Item item) { - if (item instanceof SandboxInternal.IItemWrapper) { - return ((SandboxInternal.IItemWrapper) item).getItem(); - } - return (Item) item; - } - - public static PistonBehavior convert(org.sandboxpowered.api.block.Material.PistonInteraction interaction) { - return PistonBehavior.values()[interaction.ordinal()]; - } - - public static org.sandboxpowered.api.block.Material.PistonInteraction convert(PistonBehavior behavior) { - return org.sandboxpowered.api.block.Material.PistonInteraction.values()[behavior.ordinal()]; - } - - public static B cast(A a, Class bClass) { - return bClass.cast(a); - } - - private static B castOrWrap(A a, Class bClass, Function wrapper) { - if (bClass.isInstance(a)) - return bClass.cast(a); - return wrapper.apply(a); - } - - public static Settings convert(Block.Settings settings) { - return castOrWrap(settings, Settings.class, prop -> { - Settings vs = Settings.of(convert(settings.getMaterial())); - SandboxInternal.MaterialInternal ms = (SandboxInternal.MaterialInternal) vs; - vs.velocityMultiplier(settings.getVelocity()); - vs.jumpVelocityMultiplier(settings.getJumpVelocity()); - vs.slipperiness(settings.getSlipperiness()); - vs.strength(settings.getHardness(), settings.getResistance()); - ms.setLevel(settings.getLuminance()); - return vs; - }); - } - - public static Material convert(org.sandboxpowered.api.block.Material material) { - return castOrWrap(material, Material.class, m -> null); - } - - public static org.sandboxpowered.api.block.Material convert(Material material) { - return castOrWrap(material, org.sandboxpowered.api.block.Material.class, m -> null); - } - - public static int convert(BlockFlag[] flags) { - int r = 0b00000; - for (BlockFlag flag : flags) { - switch (flag) { - case NOTIFY_NEIGHBORS: - r |= 0b00001; - continue; - case SEND_TO_CLIENT: - r |= 0b00010; - continue; - case NO_RERENDER: - r |= 0b00100; - continue; - case RERENDER_MAIN_THREAD: - r |= 0b01000; - continue; - case NO_OBSERVER: - r |= 0b10000; - continue; - } - } - return r; - } - - public static Identifier convert(Identity identity) { - return castOrWrap(identity, Identifier.class, id -> new Identifier(id.getNamespace(), id.getPath())); - } - - public static net.minecraft.util.math.Direction convert(Direction direction) { - return net.minecraft.util.math.Direction.byId(direction.ordinal()); - } - - public static Direction convert(net.minecraft.util.math.Direction direction) { - return Direction.byId(direction.ordinal()); - } - - public static Mirror convert(BlockMirror mirror) { - return Mirror.values()[mirror.ordinal()]; - } - - public static BlockMirror convert(Mirror mirror) { - return BlockMirror.values()[mirror.ordinal()]; - } - - public static Rotation convert(BlockRotation rotation) { - return Rotation.values()[rotation.ordinal()]; - } - - public static BlockRotation convert(Rotation rotation) { - return BlockRotation.values()[rotation.ordinal()]; - } - - public static BlockView convert(WorldReader reader) { - return castOrWrap(reader, BlockView.class, read -> null); - } - - public static net.minecraft.world.World convert(World reader) { - return castOrWrap(reader, net.minecraft.world.World.class, read -> null); - } - - public static World convert(net.minecraft.world.World world) { - return castOrWrap(world, World.class, read -> null); - } - - public static net.minecraft.block.entity.BlockEntity convert(BlockEntity entity) { - return castOrWrap(entity, net.minecraft.block.entity.BlockEntity.class, read -> BlockEntityWrapper.create(entity)); - } - - public static BlockEntity convert(net.minecraft.block.entity.BlockEntity entity) { - if (entity instanceof BlockEntityWrapper) - return ((BlockEntityWrapper) entity).getBlockEntity(); - return (BlockEntity) entity; - } - - public static net.minecraft.item.ItemStack convert(ItemStack itemStack) { - return cast(itemStack, net.minecraft.item.ItemStack.class); - } - - public static ItemStack convert(net.minecraft.item.ItemStack itemStack) { - return cast(itemStack, ItemStack.class); - } - - public static EntityType convert(Entity.Type type) { - return cast(type, EntityType.class); - } - - public static Entity.Type convert(EntityType type) { - return cast(type, Entity.Type.class); - } - - public static Text convert(org.sandboxpowered.api.util.text.Text type) { - return cast(type, Text.class); - } - - public static Block convert(net.minecraft.block.Block block) { - if (block instanceof SandboxInternal.IBlockWrapper) - return ((SandboxInternal.IBlockWrapper) block).getBlock(); - return (Block) block; - } - - public static Entity convert(net.minecraft.entity.Entity entity) { - return (Entity) entity; - } - - public static PlayerEntity convert(net.minecraft.entity.player.PlayerEntity player) { - return (PlayerEntity) player; - } - - public static net.minecraft.entity.player.PlayerEntity convert(PlayerEntity player) { - return (net.minecraft.entity.player.PlayerEntity) player; - } - - public static net.minecraft.entity.Entity convert(Entity entity) { - return (net.minecraft.entity.Entity) entity; - } - - public static > Property convert(org.sandboxpowered.api.state.Property property) { - if (property instanceof EnumPropertyWrapper) { - return (Property) ((EnumPropertyWrapper) property).getEnumProperty(); - } - //TODO: Wrapper - return (Property) property; - } - - public static Fluid convert(net.minecraft.fluid.Fluid fluid) { - if (fluid instanceof FluidWrapper) - return ((FluidWrapper) fluid).getFluid(); - return (Fluid) fluid; - } - - public static net.minecraft.fluid.Fluid convert(Fluid fluid) { - return castOrWrap(fluid, net.minecraft.fluid.Fluid.class, WrappingUtil::getWrapped); - } - - public static net.minecraft.item.Item.Settings convert(Item.Settings settings) { - return new net.minecraft.item.Item.Settings().maxCount(settings.getStackSize()).maxDamage(settings.getMaxDamage()).recipeRemainder(settings.getRecipeRemainder() == null ? null : convert(settings.getRecipeRemainder())); - } - - public static ActionResult convert(InteractionResult result) { - switch (result) { - case SUCCESS: - return ActionResult.SUCCESS; - case CONSUME: - return ActionResult.CONSUME; - case FAILURE: - return ActionResult.FAIL; - default: - case IGNORE: - return ActionResult.PASS; - } - } - - public static InteractionResult convert(ActionResult result) { - switch (result) { - case SUCCESS: - return InteractionResult.SUCCESS; - case CONSUME: - return InteractionResult.CONSUME; - case FAIL: - return InteractionResult.FAILURE; - default: - case PASS: - return InteractionResult.IGNORE; - } - } - - public static CompoundTag convert(ReadableCompoundTag tag) { - return (net.minecraft.nbt.CompoundTag) tag; - } - - public static WorldReader convert(BlockView view) { - return cast(view, WorldReader.class); - } - - public static Vector3d convertToVector(org.sandboxpowered.api.util.math.Vec3d vec3) { - return cast(vec3, Vector3d.class); - } - - public static Vec3d convertToVec(org.sandboxpowered.api.util.math.Vec3d vec3) { - return cast(vec3, Vec3d.class); - } - - public static RegistryKey convertToRegistryKey(RegistryKey> registryKey, Identity identity) { - return RegistryKey.of(registryKey, convert(identity)); - } - - public static FluidState convert(org.sandboxpowered.api.state.FluidState state) { - return (FluidState) (Object) state; - } - - public static org.sandboxpowered.api.state.FluidState convert(FluidState state) { - return (org.sandboxpowered.api.state.FluidState) (Object) state; - } - - public static BlockState convert(net.minecraft.block.BlockState state) { - return (BlockState) state; - } - - public static net.minecraft.enchantment.Enchantment.Rarity convert(Enchantment.Rarity rarity) { - switch (rarity) { - case UNCOMMON: - return net.minecraft.enchantment.Enchantment.Rarity.UNCOMMON; - case RARE: - return net.minecraft.enchantment.Enchantment.Rarity.RARE; - case VERY_RARE: - return net.minecraft.enchantment.Enchantment.Rarity.VERY_RARE; - case COMMON: - default: - return net.minecraft.enchantment.Enchantment.Rarity.COMMON; - } - } - - public static GraphicsMode convert(net.minecraft.client.options.GraphicsMode graphicsMode) { - switch (graphicsMode) { - case FAST: - return GraphicsMode.FAST; - case FANCY: - return GraphicsMode.FANCY; - case FABULOUS: - return GraphicsMode.FABULOUS; - } - return GraphicsMode.FAST; - } - - public static org.sandboxpowered.api.util.math.Vec3d convert(Vec3d pos) { - return (org.sandboxpowered.api.util.math.Vec3d) pos; - } - - public static Direction.Axis convert(net.minecraft.util.math.Direction.Axis axis) { - switch (axis) { - case X: - return Direction.Axis.X; - case Y: - return Direction.Axis.Y; - case Z: - return Direction.Axis.Z; - } - return Direction.Axis.X; - } - - public static net.minecraft.util.math.Direction.Axis convert(Direction.Axis axis) { - switch (axis) { - case X: - return net.minecraft.util.math.Direction.Axis.X; - case Y: - return net.minecraft.util.math.Direction.Axis.Y; - case Z: - return net.minecraft.util.math.Direction.Axis.Z; - } - return net.minecraft.util.math.Direction.Axis.X; - } - - public static SlabType convert(net.minecraft.block.enums.SlabType slabType) { - switch (slabType) { - case TOP: - return SlabType.TOP; - case BOTTOM: - return SlabType.BOTTOM; - case DOUBLE: - return SlabType.DOUBLE; - } - return SlabType.BOTTOM; - } - - public static net.minecraft.block.enums.SlabType convert(SlabType slabType) { - switch (slabType) { - case TOP: - return net.minecraft.block.enums.SlabType.TOP; - case BOTTOM: - return net.minecraft.block.enums.SlabType.BOTTOM; - case DOUBLE: - return net.minecraft.block.enums.SlabType.DOUBLE; - } - return net.minecraft.block.enums.SlabType.BOTTOM; - } - - public static Shape convert(VoxelShape shape) { - return (Shape) shape; - } - - public static VoxelShape convert(Shape shape) { - return (VoxelShape) shape; - } - - public static Box convert(net.minecraft.util.math.Box boundingBox) { - return (Box) boundingBox; - } - - public static net.minecraft.util.math.Box convert(Box box) { - return (net.minecraft.util.math.Box) box; - } - - public static Hand convert(org.sandboxpowered.api.entity.player.Hand hand) { - return hand == org.sandboxpowered.api.entity.player.Hand.MAIN_HAND ? Hand.MAIN_HAND : Hand.OFF_HAND; - } - public static org.sandboxpowered.api.entity.player.Hand convert(Hand hand) { - return hand == Hand.MAIN_HAND ? org.sandboxpowered.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.api.entity.player.Hand.OFF_HAND; - } - - public static EquipmentSlot convert(LivingEntity.EquipmentSlot slot) { - switch (slot) { - case FEET: - return EquipmentSlot.FEET; - case HEAD: - return EquipmentSlot.HEAD; - case LEGS: - return EquipmentSlot.LEGS; - case CHEST: - return EquipmentSlot.CHEST; - case OFFHAND: - return EquipmentSlot.OFFHAND; - case MAINHAND: - return EquipmentSlot.MAINHAND; - } - return null; - } - - public static MatrixStack convert(org.sandboxpowered.api.util.math.MatrixStack stack) { - return cast(stack, MatrixStack.class); - } - - public static org.sandboxpowered.api.util.math.MatrixStack convert(MatrixStack stack) { - return cast(stack, org.sandboxpowered.api.util.math.MatrixStack.class); - } - - public static VertexConsumer.Provider convert(VertexConsumerProvider consumerProvider) { - return null; - } - - @Nullable - public static net.minecraft.entity.LivingEntity convertToLivingOrNull(Entity entity) { - if (entity instanceof net.minecraft.entity.LivingEntity) - return (net.minecraft.entity.LivingEntity) entity; - return null; - } - - public static BlockEntityType convert(BlockEntity.Type type) { - return cast(type, BlockEntityType.class); - } - - public static BlockEntity.Type convert(BlockEntityType type) { - return cast(type, BlockEntity.Type.class); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/UnknownComponentException.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/UnknownComponentException.java deleted file mode 100644 index 34dec77..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/UnknownComponentException.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.exception; - -public class UnknownComponentException extends RuntimeException { - public UnknownComponentException(Class xClass) { - super("Unknown component "+xClass); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/WrappingException.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/WrappingException.java deleted file mode 100644 index a80a087..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/exception/WrappingException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.exception; - -public class WrappingException extends RuntimeException { - public WrappingException(String message) { - super(message); - } - - public WrappingException(Class clazz) { - super(String.format("Unacceptable class '%s'", clazz)); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/math/Vec2iImpl.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/math/Vec2iImpl.java deleted file mode 100644 index d40d44f..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/math/Vec2iImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.math; - -import org.sandboxpowered.api.util.math.Vec2i; - -public class Vec2iImpl implements Vec2i { - private final int x; - private final int y; - - public Vec2iImpl(int x, int y) { - this.x = x; - this.y = y; - } - - @Override - public int getX() { - return x; - } - - @Override - public int getY() { - return y; - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityCTXWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityCTXWrapper.java deleted file mode 100644 index 66b0bb8..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityCTXWrapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.block.entity.BlockEntity; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.internal.BlockEntityContext; - -public class BlockEntityCTXWrapper implements BlockEntityContext { - private final BlockEntity entity; - - BlockEntityCTXWrapper(BlockEntity entity) { - this.entity = entity; - } - - @Override - public World getWorld() { - return (World) entity.getWorld(); - } - - @Override - public Position getPosition() { - return (Position) entity.getPos(); - } - - @Override - public void save() { - entity.markDirty(); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityWrapper.java deleted file mode 100644 index 95f0333..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockEntityWrapper.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.Tickable; -import org.jetbrains.annotations.NotNull; -import org.sandboxpowered.api.block.entity.BaseBlockEntity; -import org.sandboxpowered.api.block.entity.BlockEntity; -import org.sandboxpowered.api.util.nbt.ReadableCompoundTag; -import org.sandboxpowered.api.util.nbt.WritableCompoundTag; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -public class BlockEntityWrapper extends net.minecraft.block.entity.BlockEntity { - private final BlockEntity blockEntity; - - public BlockEntityWrapper(@NotNull BlockEntity blockEntity) { - super(WrappingUtil.convert(blockEntity.getType())); - this.blockEntity = blockEntity; - if (this.blockEntity instanceof BaseBlockEntity) { - ((BaseBlockEntity) this.blockEntity).setContext(new BlockEntityCTXWrapper(this)); - } - } - - public static BlockEntityWrapper create(BlockEntity blockEntity) { - if (blockEntity instanceof BlockEntity.Tickable) - return new BlockEntityWrapper.Ticking((BlockEntity.Tickable) blockEntity); - return new BlockEntityWrapper(blockEntity); - } - - public BlockEntity getBlockEntity() { - return blockEntity; - } - - @Override - public void fromTag(BlockState blockState, CompoundTag tag) { - super.fromTag(blockState, tag); - blockEntity.read((ReadableCompoundTag) tag); - } - - @Override - public CompoundTag toTag(CompoundTag tag) { - super.toTag(tag); - blockEntity.write((WritableCompoundTag) tag); - return tag; - } - - public static class Ticking extends BlockEntityWrapper implements Tickable { - private final BlockEntity.Tickable tickableBlockEntity; - - public Ticking(BlockEntity.Tickable blockEntity) { - super(blockEntity); - this.tickableBlockEntity = blockEntity; - } - - @Override - public void tick() { - tickableBlockEntity.onTick(); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockPosWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockPosWrapper.java deleted file mode 100644 index c5bcf87..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockPosWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.util.math.BlockPos; -import org.sandboxpowered.api.util.math.Position; - -public class BlockPosWrapper extends BlockPos { - private final Position position; - - public BlockPosWrapper(Position position) { - super(position.getX(), position.getY(), position.getZ()); - this.position = position; - } - - @Override - public int getX() { - return position.getX(); - } - - @Override - public int getY() { - return position.getY(); - } - - @Override - public int getZ() { - return position.getZ(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o instanceof BlockPos) - return position.equals(o); - return false; - } - - @Override - public int hashCode() { - return position.hashCode(); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockWrapper.java deleted file mode 100644 index e356514..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/BlockWrapper.java +++ /dev/null @@ -1,439 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.piston.PistonBehavior; -import net.minecraft.client.util.math.Vector3f; -import net.minecraft.entity.LivingEntity; -import net.minecraft.fluid.FlowableFluid; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.StateManager; -import net.minecraft.util.ActionResult; -import net.minecraft.util.BlockMirror; -import net.minecraft.util.BlockRotation; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.block.BaseBlock; -import org.sandboxpowered.api.block.Block; -import org.sandboxpowered.api.component.Components; -import org.sandboxpowered.api.component.FluidContainer; -import org.sandboxpowered.api.entity.Entity; -import org.sandboxpowered.api.entity.player.PlayerEntity; -import org.sandboxpowered.api.fluid.FluidStack; -import org.sandboxpowered.api.fluid.Fluids; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.util.math.Vec3f; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -@SuppressWarnings("unchecked") -public class BlockWrapper extends net.minecraft.block.Block implements SandboxInternal.IBlockWrapper { - public final Block block; - public final StateManager wrappedStateManager; - private final StateFactory sandboxWrappedFactory; - - public BlockWrapper(Block block) { - super(WrappingUtil.convert(block.getSettings())); - this.block = block; - StateManager.Builder builder = new StateManager.Builder<>(this); - this.appendProperties(builder); - this.wrappedStateManager = builder.build(net.minecraft.block.Block::getDefaultState, BlockState::new); - this.setDefaultState(wrappedStateManager.getDefaultState()); - this.sandboxWrappedFactory = new StateFactoryImpl<>(wrappedStateManager, b -> (Block) b, s -> (org.sandboxpowered.api.state.BlockState) s); - ((SandboxInternal.StateFactory) wrappedStateManager).setSboxFactory(sandboxWrappedFactory); - if (this.block instanceof BaseBlock) - ((BaseBlock) this.block).setStateFactory(sandboxWrappedFactory); - setDefaultState(WrappingUtil.convert(this.block.getBaseState())); - } - - public static SandboxInternal.IBlockWrapper create(Block block) { - if (block instanceof org.sandboxpowered.api.block.FluidBlock) - return new WithFluid((FlowableFluid) WrappingUtil.convert(((org.sandboxpowered.api.block.FluidBlock) block).getFluid()), block); - if (block instanceof FluidContainer) { - if (block.hasBlockEntity()) { - return new BlockWrapper.WithWaterloggableBlockEntity(block); - } - return new BlockWrapper.WithWaterloggable(block); - } - if (block.hasBlockEntity()) { - return new BlockWrapper.WithBlockEntity(block); - } - return new BlockWrapper(block); - } - - private static ActionResult staticOnUse(org.sandboxpowered.api.state.BlockState state, org.sandboxpowered.api.world.World world, Position pos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult, Block block) { - @SuppressWarnings("ConstantConditions") InteractionResult result = block.onBlockUsed( - world, - pos, - state, - player, - hand == Hand.MAIN_HAND ? org.sandboxpowered.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.api.entity.player.Hand.OFF_HAND, - WrappingUtil.convert(blockHitResult.getSide()), - (Vec3f) (Object) new Vector3f(blockHitResult.getPos()) - ); - return WrappingUtil.convert(result); - } - - @Override - public ItemStack getPickStack(BlockView blockView, BlockPos blockPos, BlockState blockState) { - return WrappingUtil.convert(this.block.getPickStack( - WrappingUtil.convert(blockView), - WrappingUtil.convert(blockPos), - WrappingUtil.convert(blockState) - )); - } - - @Override - public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext) { - return WrappingUtil.convert(block.getShape( - WrappingUtil.convert(blockView), - WrappingUtil.convert(blockPos), - WrappingUtil.convert(blockState) - )); - } - - @Override - public StateManager getStateManager() { - if (wrappedStateManager == null) - return super.getStateManager(); - return wrappedStateManager; - } - - @Override - protected void appendProperties(StateManager.Builder stateBuilder) { - super.appendProperties(stateBuilder); - if (block instanceof BaseBlock) - ((BaseBlock) block).appendProperties(((SandboxInternal.StateFactoryBuilder) stateBuilder).getSboxBuilder()); - } - - @Override - public Block getBlock() { - return block; - } - - @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, net.minecraft.entity.player.PlayerEntity player, Hand hand, BlockHitResult hitResult) { - return staticOnUse((org.sandboxpowered.api.state.BlockState) state, (org.sandboxpowered.api.world.World) world, (Position) pos, (PlayerEntity) player, hand, hitResult, block); - } - - @Nullable - @Override - public BlockState getPlacementState(ItemPlacementContext context) { - return WrappingUtil.convert(block.getStateForPlacement( - WrappingUtil.convert(context.getWorld()), - WrappingUtil.convert(context.getBlockPos()), - WrappingUtil.convert(context.getPlayer()), - context.getHand() == Hand.MAIN_HAND ? org.sandboxpowered.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.api.entity.player.Hand.OFF_HAND, - WrappingUtil.convert(context.getStack()), - WrappingUtil.convert(context.getSide()), - WrappingUtil.convert(context.getHitPos()) - )); - } - - @Override - public void onBlockBreakStart(BlockState state, World world, BlockPos pos, net.minecraft.entity.player.PlayerEntity player) { - block.onBlockClicked( - WrappingUtil.convert(world), - WrappingUtil.convert(pos), - WrappingUtil.convert(state), - WrappingUtil.convert(player) - ); - } - - @Override - public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, net.minecraft.item.ItemStack stack) { - block.onBlockPlaced( - WrappingUtil.convert(world), - WrappingUtil.convert(pos), - WrappingUtil.convert(state), - WrappingUtil.convert(entity), - WrappingUtil.convert(stack) - ); - } - - @Override - public void onBroken(WorldAccess world, BlockPos pos, BlockState state) { - block.onBlockBroken( - (org.sandboxpowered.api.world.World) world, - (Position) pos, - (org.sandboxpowered.api.state.BlockState) state - ); - } - - @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState otherState, WorldAccess world, BlockPos pos, BlockPos otherPos) { - return WrappingUtil.convert(block.updateOnNeighborChanged( - (org.sandboxpowered.api.state.BlockState) state, - WrappingUtil.convert(direction), - (org.sandboxpowered.api.state.BlockState) otherState, - (org.sandboxpowered.api.world.World) world, (Position) pos, - (Position) otherPos - )); - } - - @Override - public BlockState rotate(BlockState state, BlockRotation rotation) { - return WrappingUtil.convert(block.rotate( - (org.sandboxpowered.api.state.BlockState) state, - WrappingUtil.convert(rotation) - )); - } - - @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { - return WrappingUtil.convert(block.mirror( - (org.sandboxpowered.api.state.BlockState) state, - WrappingUtil.convert(mirror) - )); - } - - @Override - public boolean canReplace(BlockState state, ItemPlacementContext context) { - return block.canReplace( - WrappingUtil.convert(context.getWorld()), - WrappingUtil.convert(context.getBlockPos()), - WrappingUtil.convert(state), - WrappingUtil.convert(context.getPlayer()), - context.getHand() == Hand.MAIN_HAND ? org.sandboxpowered.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.api.entity.player.Hand.OFF_HAND, - WrappingUtil.convert(context.getStack()), - WrappingUtil.convert(context.getSide()), - WrappingUtil.convert(context.getHitPos()) - ); - } - - @Override - public void onSteppedOn(World world, BlockPos pos, net.minecraft.entity.Entity entity) { - block.onEntityWalk( - WrappingUtil.convert(world), - WrappingUtil.convert(pos), - WrappingUtil.convert(entity) - ); - } - - @Override - public PistonBehavior getPistonBehavior(BlockState state) { - return WrappingUtil.convert(block.getPistonInteraction((org.sandboxpowered.api.state.BlockState) state)); - } - - @Override - public boolean canMobSpawnInside() { - return block.canEntitySpawnWithin(block.getBaseState()); - } - - public static class WithFluid extends FluidBlock implements SandboxInternal.IBlockWrapper { - private final Block block; - - public WithFluid(FlowableFluid basefluid, Block block) { - super(basefluid, WrappingUtil.convert(block.getSettings())); - this.block = block; - if (this.block instanceof BaseBlock) - ((BaseBlock) this.block).setStateFactory(((SandboxInternal.StateFactoryHolder) this).getSandboxStateFactory()); - } - - @Override - protected void appendProperties(StateManager.Builder stateBuilder) { - super.appendProperties(stateBuilder); - if (block instanceof org.sandboxpowered.api.block.FluidBlock) - ((BaseBlock) block).appendProperties(((SandboxInternal.StateFactoryBuilder) stateBuilder).getSboxBuilder()); - } - - @Override - public Block getBlock() { - return block; - } - - @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, net.minecraft.entity.player.PlayerEntity player, Hand hand, BlockHitResult hitResult) { - return staticOnUse((org.sandboxpowered.api.state.BlockState) state, (org.sandboxpowered.api.world.World) world, (Position) pos, (PlayerEntity) player, hand, hitResult, block); - } - - @Override - public ItemStack getPickStack(BlockView blockView, BlockPos blockPos, BlockState blockState) { - return WrappingUtil.convert(this.block.getPickStack( - WrappingUtil.convert(blockView), - WrappingUtil.convert(blockPos), - WrappingUtil.convert(blockState) - )); - } - - @Override - public void onBlockBreakStart(BlockState state, World world, BlockPos pos, net.minecraft.entity.player.PlayerEntity player) { - block.onBlockClicked( - (org.sandboxpowered.api.world.World) world, - (Position) pos, - (org.sandboxpowered.api.state.BlockState) state, - (PlayerEntity) player - ); - } - - @Override - public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity livingentity, net.minecraft.item.ItemStack stack) { - block.onBlockPlaced( - (org.sandboxpowered.api.world.World) world, - (Position) pos, - (org.sandboxpowered.api.state.BlockState) state, - (Entity) livingentity, - WrappingUtil.convert(stack) - ); - } - - @Override - public void onBroken(WorldAccess world, BlockPos pos, BlockState state) { - block.onBlockBroken( - (org.sandboxpowered.api.world.World) world, - (Position) pos, - (org.sandboxpowered.api.state.BlockState) state - ); - } - - @Override - public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState otherState, WorldAccess world, BlockPos pos, BlockPos otherPos) { - return WrappingUtil.convert(block.updateOnNeighborChanged( - (org.sandboxpowered.api.state.BlockState) state, WrappingUtil.convert(direction), (org.sandboxpowered.api.state.BlockState) otherState, (org.sandboxpowered.api.world.World) world, - (Position) pos, - (Position) otherPos - )); - } - - @Override - public BlockState rotate(BlockState state, BlockRotation rotation) { - return WrappingUtil.convert(block.rotate( - (org.sandboxpowered.api.state.BlockState) state, - WrappingUtil.convert(rotation) - )); - } - - @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { - return WrappingUtil.convert(block.mirror( - (org.sandboxpowered.api.state.BlockState) state, - WrappingUtil.convert(mirror) - )); - } - - @Override - public boolean canReplace(BlockState state, ItemPlacementContext context) { - return block.canReplace( - WrappingUtil.convert(context.getWorld()), - WrappingUtil.convert(context.getBlockPos()), - WrappingUtil.convert(state), - WrappingUtil.convert(context.getPlayer()), - context.getHand() == Hand.MAIN_HAND ? org.sandboxpowered.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.api.entity.player.Hand.OFF_HAND, - WrappingUtil.convert(context.getStack()), - WrappingUtil.convert(context.getSide()), - WrappingUtil.convert(context.getHitPos()) - ); - } - - @Override - public void onSteppedOn(World world, BlockPos pos, net.minecraft.entity.Entity entity) { - block.onEntityWalk( - (org.sandboxpowered.api.world.World) world, - (Position) pos, - WrappingUtil.convert(entity) - ); - } - - @Override - public PistonBehavior getPistonBehavior(BlockState state) { - return WrappingUtil.convert(block.getPistonInteraction((org.sandboxpowered.api.state.BlockState) state)); - } - - @Override - public boolean canMobSpawnInside() { - return block.canEntitySpawnWithin(block.getBaseState()); - } - } - - public static class WithBlockEntity extends BlockWrapper implements BlockEntityProvider { - public WithBlockEntity(Block block) { - super(block); - } - - @Nullable - @Override - public BlockEntity createBlockEntity(BlockView var1) { - return WrappingUtil.convert(getBlock().createBlockEntity((WorldReader) var1)); - } - } - - public static class WithWaterloggable extends BlockWrapper implements Waterloggable { - private final FluidContainer container; - - public WithWaterloggable(Block block) { - super(block); - this.container = (FluidContainer) block; - } - - public FluidContainer getContainer() { - return container; - } - - @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { - return ((org.sandboxpowered.api.state.BlockState) state).getComponent( - WrappingUtil.convert(world), - (Position) pos, - Components.FLUID_COMPONENT - ).map(tank -> - tank.insert(FluidStack.of(WrappingUtil.convert(fluid), 1000), true).isEmpty() - ).orElse(false); - } - - @Override - public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) { - return ((org.sandboxpowered.api.state.BlockState) state).getComponent( - WrappingUtil.convert(world), - (Position) pos, - Components.FLUID_COMPONENT - ).map(tank -> { - FluidStack filled = FluidStack.of(WrappingUtil.convert(fluidState.getFluid()), 1000); - FluidStack ret = tank.insert(filled, true); - if (ret.isEmpty()) { - tank.insert(filled); - return true; - } else { - return false; - } - }).orElse(false); - } - - @Override - public Fluid tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) { - return WrappingUtil.convert( - ((org.sandboxpowered.api.state.BlockState) state).getComponent( - WrappingUtil.convert(world), - (Position) pos, - Components.FLUID_COMPONENT - ).map(tank -> - tank.extract(1000).getFluid() - ).orElse(Fluids.EMPTY.get()) - ); - } - } - - public static class WithWaterloggableBlockEntity extends BlockWrapper.WithWaterloggable implements BlockEntityProvider { - public WithWaterloggableBlockEntity(Block block) { - super(block); - } - - @Nullable - @Override - public BlockEntity createBlockEntity(BlockView var1) { - return WrappingUtil.convert(getBlock().createBlockEntity((WorldReader) var1)); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnchantmentWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnchantmentWrapper.java deleted file mode 100644 index 6f51445..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnchantmentWrapper.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.enchantment.EnchantmentTarget; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import org.sandboxpowered.api.enchantment.Enchantment; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -public class EnchantmentWrapper extends net.minecraft.enchantment.Enchantment { - private final Enchantment enchantment; - - public EnchantmentWrapper(Enchantment enchantment) { - super(WrappingUtil.convert(enchantment.getRarity()), EnchantmentTarget.WEARABLE, EquipmentSlot.values()); //TODO: Allow sandbox enchants to specify these values - this.enchantment = enchantment; - } - - @Override - public int getMinLevel() { - return enchantment.getMinimumLevel(); - } - - @Override - public int getMaxLevel() { - return enchantment.getMaximumLevel(); - } - - @Override - public boolean isAcceptableItem(ItemStack stack) { - return enchantment.isAcceptableItem(WrappingUtil.cast(stack, org.sandboxpowered.api.item.ItemStack.class)); - } - - @Override - public boolean isTreasure() { - return enchantment.isTreasure(); - } - - @Override - public boolean isCursed() { - return enchantment.isCurse(); - } - - @Override - public Rarity getRarity() { - return WrappingUtil.convert(enchantment.getRarity()); - } - - @Override - public void onTargetDamaged(LivingEntity livingEntity, Entity entity, int i) { - enchantment.onTargetDamage((org.sandboxpowered.api.entity.LivingEntity) WrappingUtil.convert(livingEntity), WrappingUtil.convert(entity), i); - } - - @Override - public void onUserDamaged(LivingEntity livingEntity, Entity entity, int i) { - enchantment.onUserDamage((org.sandboxpowered.api.entity.LivingEntity) WrappingUtil.convert(livingEntity), WrappingUtil.convert(entity), i); - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnumPropertyWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnumPropertyWrapper.java deleted file mode 100644 index c285e04..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/EnumPropertyWrapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - - -import net.minecraft.state.property.EnumProperty; -import net.minecraft.util.StringIdentifiable; -import org.sandboxpowered.api.state.Property; - -import java.util.Collection; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class EnumPropertyWrapper, V extends Enum & StringIdentifiable> implements Property { - private final EnumProperty enumProperty; - private final Function v2SFunction; - private final Function s2VFunction; - private final Class valueType; - - public EnumPropertyWrapper(EnumProperty enumProperty, Function v2SFunction, Function s2VFunction, Class valueType) { - this.enumProperty = enumProperty; - this.v2SFunction = v2SFunction; - this.s2VFunction = s2VFunction; - this.valueType = valueType; - } - - public EnumProperty getEnumProperty() { - return enumProperty; - } - - public Function getV2SFunction() { - return v2SFunction; - } - - public Function getS2VFunction() { - return s2VFunction; - } - - @Override - public String getName() { - return enumProperty.getName(); - } - - @Override - public String getName(S value) { - return enumProperty.name(s2VFunction.apply(value)); - } - - @Override - public Collection getValues() { - return enumProperty.getValues().stream().map(v2SFunction).collect(Collectors.toSet()); - } - - @Override - public Class getValueType() { - return valueType; - } - - @Override - public Optional getValue(String name) { - return enumProperty.parse(name).map(v2SFunction); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/FluidWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/FluidWrapper.java deleted file mode 100644 index eaadbeb..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/FluidWrapper.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.item.Item; -import net.minecraft.state.StateManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockView; -import net.minecraft.world.WorldAccess; -import net.minecraft.world.WorldView; -import org.sandboxpowered.api.fluid.BaseFluid; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.WorldReader; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.ReflectionHelper; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -import java.util.Optional; - -public class FluidWrapper extends net.minecraft.fluid.FlowableFluid { - private final BaseFluid fluid; - - public FluidWrapper(BaseFluid fluid) { - super(); - this.fluid = fluid; - StateManager.Builder fluidStateBuilder = new StateManager.Builder<>(this); - this.appendProperties(fluidStateBuilder); - try { - ReflectionHelper.setPrivateField(net.minecraft.fluid.Fluid.class, this, new String[]{"field_15905", "stateManager"}, fluidStateBuilder.build(Fluid::getDefaultState, FluidState::new)); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - this.setDefaultState(this.getStateManager().getDefaultState()); - } - - public static FluidWrapper create(BaseFluid fluid) { - return new FluidWrapper(fluid); - } - - public BaseFluid getFluid() { - return fluid; - } - - @SuppressWarnings("unchecked") - @Override - protected void appendProperties(StateManager.Builder stateBuilder) { - super.appendProperties(stateBuilder); - if (fluid != null) - fluid.appendProperties(((SandboxInternal.StateFactoryBuilder) stateBuilder).getSboxBuilder()); - } - - @Override - public net.minecraft.fluid.Fluid getFlowing() { - return WrappingUtil.convert(fluid.asFlowing()); - } - - @Override - public net.minecraft.fluid.Fluid getStill() { - return WrappingUtil.convert(fluid.asStill()); - } - - @Override - protected boolean isInfinite() { - return fluid.isInfinite(); - } - - @Override - protected void beforeBreakingBlock(WorldAccess world, BlockPos pos, BlockState state) { - BlockEntity blockEntity = state.getBlock().hasBlockEntity() ? world.getBlockEntity(pos) : null; - Block.dropStacks(state, world, pos, blockEntity); - } - - @Override - public Vec3d getVelocity(BlockView world, BlockPos pos, FluidState fluidState) { - Optional mono = fluid.getVelocity( - (WorldReader) world, - (Position) pos, - WrappingUtil.convert(fluidState) - ); - return mono.map(WrappingUtil::convertToVec).orElseGet(() -> super.getVelocity(world, pos, fluidState)); - } - - @Override - protected int getFlowSpeed(WorldView worldView) { - return 4; - } - - @Override - protected int getLevelDecreasePerBlock(WorldView world) { - return 1; - } - - @Override - public Item getBucketItem() { - return WrappingUtil.convert(fluid.asBucket()); - } - - @Override - protected boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) { - return direction == Direction.DOWN && !fluid.matchesType(this); - } - - @Override - public int getTickRate(WorldView var1) { - return fluid.getTickRate((WorldReader) var1); - } - - @Override - protected float getBlastResistance() { - return 100; - } - - @Override - public boolean matchesType(net.minecraft.fluid.Fluid fluid) { - return this.fluid.matches(WrappingUtil.convert(fluid)); - } - - @Override - protected BlockState toBlockState(FluidState var1) { - return (BlockState) fluid.asBlockState(WrappingUtil.convert(var1)); - } - - @Override - public boolean isStill(FluidState var1) { - return fluid.isStill(WrappingUtil.convert(var1)); - } - - @Override - public int getLevel(FluidState var1) { - return isStill(var1) ? 8 : var1.get(LEVEL); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/ItemWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/ItemWrapper.java deleted file mode 100644 index a70709c..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/ItemWrapper.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.block.BlockState; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import org.jetbrains.annotations.Nullable; -import org.sandboxpowered.api.item.BlockItem; -import org.sandboxpowered.api.item.BucketItem; -import org.sandboxpowered.api.item.Item; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.util.InteractionResult; -import org.sandboxpowered.api.util.math.Position; -import org.sandboxpowered.api.world.World; -import org.sandboxpowered.sandbox.fabric.internal.SandboxInternal; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -import java.util.LinkedList; -import java.util.List; - -public class ItemWrapper extends net.minecraft.item.Item implements SandboxInternal.IItemWrapper { - private final Item item; - - public ItemWrapper(Item item) { - super(WrappingUtil.convert(item.getSettings())); - this.item = item; - } - - public static SandboxInternal.IItemWrapper create(Item iItem) { - if (iItem instanceof BucketItem) - return new BucketItemWrapper((BucketItem) iItem); - if (iItem instanceof BlockItem) - return new BlockItemWrapper((BlockItem) iItem); - return new ItemWrapper(iItem); - } - - @Override - public Item getItem() { - return item; - } - - @Override - public ActionResult useOnBlock(ItemUsageContext context) { - InteractionResult result = item.onItemUsed( - (World) context.getWorld(), - (Position) context.getBlockPos(), - WrappingUtil.cast(context.getStack(), ItemStack.class) - ); - return WrappingUtil.convert(result); - } - - @Override - public float getMiningSpeedMultiplier(net.minecraft.item.ItemStack itemStack, BlockState blockState) { - return item.getMiningSpeed(WrappingUtil.convert(itemStack), WrappingUtil.convert(blockState)); - } - - @Override - public void appendTooltip(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.world.World world, List list, TooltipContext tooltipContext) { - List tooltip = new LinkedList<>(); - item.appendTooltipText( - WrappingUtil.cast(stack, ItemStack.class), - world == null ? null : (World) world, - tooltip, - tooltipContext.isAdvanced() - ); - tooltip.forEach(text -> list.add(WrappingUtil.convert(text))); - super.appendTooltip(stack, world, list, tooltipContext); - } - - public static class BlockItemWrapper extends net.minecraft.item.BlockItem implements SandboxInternal.IItemWrapper { - private final BlockItem item; - - public BlockItemWrapper(BlockItem item) { - super(WrappingUtil.convert(item.asBlock()), WrappingUtil.convert(item.getSettings())); - this.item = item; - } - - @Override - public Item getItem() { - return item; - } - - @Override - public ActionResult useOnBlock(ItemUsageContext context) { - InteractionResult result = item.onItemUsed( - (World) context.getWorld(), - (Position) context.getBlockPos(), - WrappingUtil.cast(context.getStack(), ItemStack.class) - ); - if (result == InteractionResult.IGNORE) - return super.useOnBlock(context); - return WrappingUtil.convert(result); - } - - @Override - public float getMiningSpeedMultiplier(net.minecraft.item.ItemStack itemStack, BlockState blockState) { - return item.getMiningSpeed(WrappingUtil.convert(itemStack), WrappingUtil.convert(blockState)); - } - - @Override - public void appendTooltip(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.world.World world, List list, TooltipContext tooltipContext) { - List tooltip = new LinkedList<>(); - item.appendTooltipText( - WrappingUtil.cast(stack, ItemStack.class), - world == null ? null : (World) world, - tooltip, - tooltipContext.isAdvanced() - ); - tooltip.forEach(text -> list.add(WrappingUtil.convert(text))); - super.appendTooltip(stack, world, list, tooltipContext); - } - } - - public static class BucketItemWrapper extends net.minecraft.item.BucketItem implements SandboxInternal.IItemWrapper { - private final BucketItem item; - - public BucketItemWrapper(BucketItem item) { - super(WrappingUtil.convert(item.getFluid()), WrappingUtil.convert(item.getSettings())); - this.item = item; - } - - @Override - public float getMiningSpeedMultiplier(net.minecraft.item.ItemStack itemStack, BlockState blockState) { - return item.getMiningSpeed(WrappingUtil.convert(itemStack), WrappingUtil.convert(blockState)); - } - - @Override - public Item getItem() { - return item; - } - - @Override - public ActionResult useOnBlock(ItemUsageContext context) { - InteractionResult result = item.onItemUsed( - (World) context.getWorld(), - (Position) context.getBlockPos(), - WrappingUtil.cast(context.getStack(), ItemStack.class) - ); - if (result == InteractionResult.IGNORE) - return super.useOnBlock(context); - return WrappingUtil.convert(result); - } - - @Override - public void appendTooltip(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.world.World world, List list, TooltipContext tooltipContext) { - List tooltip = new LinkedList<>(); - item.appendTooltipText( - WrappingUtil.cast(stack, ItemStack.class), - world == null ? null : (World) world, - tooltip, - tooltipContext.isAdvanced() - ); - tooltip.forEach(text -> list.add(WrappingUtil.convert(text))); - super.appendTooltip(stack, world, list, tooltipContext); - } - } -} diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/PropertyWrapper.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/PropertyWrapper.java deleted file mode 100644 index 4bc6e65..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/PropertyWrapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.state.property.Property; - -import java.util.Collection; -import java.util.Optional; - -public class PropertyWrapper> extends Property { - private final org.sandboxpowered.api.state.Property property; - - public PropertyWrapper(org.sandboxpowered.api.state.Property property) { - super(property.getName(), property.getValueType()); - this.property = property; - } - - @Override - public Collection getValues() { - return property.getValues(); - } - - @Override - public String name(T comparable) { - return property.getName(comparable); - } - - @Override - public Optional parse(String string) { - return property.getValue(string); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/SidedRespective.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/SidedRespective.java deleted file mode 100644 index 253b2a6..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/SidedRespective.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import net.minecraft.inventory.SidedInventory; -import org.apache.commons.lang3.ArrayUtils; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.api.util.Direction; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -import java.util.function.Predicate; - -public class SidedRespective extends V2SInventory { - private final Direction direction; - private final SidedInventory sidedInventory; - - public SidedRespective(SidedInventory sidedInventory, Direction direction) { - super(sidedInventory); - this.direction = direction; - this.sidedInventory = sidedInventory; - } - - @Override - public int getMaxStackSize(int slot) { - if (ArrayUtils.contains(sidedInventory.getAvailableSlots(WrappingUtil.convert(direction)), slot)) - return super.getMaxStackSize(slot); - return 0; - } - - @Override - public ItemStack get(int slot) { - if (ArrayUtils.contains(sidedInventory.getAvailableSlots(WrappingUtil.convert(direction)), slot)) - return super.get(slot); - return ItemStack.empty(); - } - - @Override - public ItemStack extract(int slot, Predicate itemFilter, int amount, boolean simulate) { - if (ArrayUtils.contains(sidedInventory.getAvailableSlots(WrappingUtil.convert(direction)), slot) && sidedInventory.canExtract(slot, WrappingUtil.cast(get(slot), net.minecraft.item.ItemStack.class), WrappingUtil.convert(direction))) - return super.extract(slot, itemFilter, amount, simulate); - return ItemStack.empty(); - } - - @Override - public ItemStack insert(int slot, ItemStack stack, boolean simulate) { - if (ArrayUtils.contains(sidedInventory.getAvailableSlots(WrappingUtil.convert(direction)), slot) && sidedInventory.canInsert(slot, WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class), WrappingUtil.convert(direction))) - return super.insert(slot, stack, simulate); - return stack; - } - - @Override - public void setStack(int slot, ItemStack stack) { - if (ArrayUtils.contains(sidedInventory.getAvailableSlots(WrappingUtil.convert(direction)), slot)) - super.setStack(slot, stack); - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/StateFactoryImpl.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/StateFactoryImpl.java deleted file mode 100644 index c3986dd..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/StateFactoryImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import org.sandboxpowered.api.state.Property; -import org.sandboxpowered.api.state.PropertyContainer; -import org.sandboxpowered.api.state.StateFactory; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -import java.util.Collection; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class StateFactoryImpl, V, A extends net.minecraft.state.State> implements StateFactory { - private final net.minecraft.state.StateManager vanilla; - private final Function vTS; - private final Function aTS; - - public StateFactoryImpl(net.minecraft.state.StateManager vanilla, Function vTS, Function aTS) { - this.vanilla = vanilla; - this.vTS = vTS; - this.aTS = aTS; - } - - @Override - public S getBaseState() { - return aTS.apply(vanilla.getDefaultState()); - } - - @Override - public T getBaseObject() { - return vTS.apply(vanilla.getOwner()); - } - - @Override - public Collection getValidStates() { - return vanilla.getStates().stream().map(aTS).collect(Collectors.toList()); - } - - public static class BuilderImpl, V, A extends net.minecraft.state.State> implements StateFactory.Builder { - private final net.minecraft.state.StateManager.Builder vaBuilder; - - public BuilderImpl(net.minecraft.state.StateManager.Builder vaBuilder) { - this.vaBuilder = vaBuilder; - } - - public Builder add(Property... properties) { - for (Property property : properties) - vaBuilder.add(WrappingUtil.convert(property)); - return this; - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/V2SInventory.java b/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/V2SInventory.java deleted file mode 100644 index 4498ac9..0000000 --- a/src/main/java/org/sandboxpowered/sandbox/fabric/util/wrapper/V2SInventory.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.sandboxpowered.sandbox.fabric.util.wrapper; - -import org.sandboxpowered.api.component.Inventory; -import org.sandboxpowered.api.item.ItemStack; -import org.sandboxpowered.sandbox.fabric.util.WrappingUtil; - -import java.util.function.Predicate; - -public class V2SInventory implements Inventory { - protected final net.minecraft.inventory.Inventory inventory; - - public V2SInventory(net.minecraft.inventory.Inventory inventory) { - this.inventory = inventory; - } - - @Override - public boolean isEmpty() { - return inventory.isEmpty(); - } - - @Override - public int getSize() { - return inventory.size(); - } - - @Override - public int getMaxStackSize(int slot) { - return Math.min(inventory.getMaxCountPerStack(), get(slot).getMaxCount()); - } - - @Override - public ItemStack get(int slot) { - return WrappingUtil.cast(inventory.getStack(slot), ItemStack.class); - } - - @Override - public ItemStack extract(int slot, Predicate itemFilter, int amount, boolean simulate) { - ItemStack out = get(slot).copy(); - out.setCount(Math.min(out.getCount(), amount)); - - if (!itemFilter.test(out)) - return ItemStack.empty(); - - if (!simulate) { - out = WrappingUtil.cast(inventory.removeStack(slot, amount), ItemStack.class); - } - - return out; - } - - @Override - public ItemStack insert(int slot, ItemStack stack, boolean simulate) { - ItemStack in = get(slot); - int max = getMaxStackSize(slot); - if (in.isEmpty()) { - ItemStack coming = stack.copy(); - if (coming.getCount() > max) { - coming.setCount(max); - } - if (!simulate) - setStack(slot, coming); - return stack.copy().shrink(coming.getCount()); - } else { - int count = in.getCount(); - if (count >= max || !in.isEqualTo(stack) || !in.areTagsEqual(stack)) - return stack; - ItemStack coming = stack.copy(); - if (count + coming.getCount() > max) { - coming.setCount(max - count); - } - if (!simulate) - setStack(slot, in.copy().grow(coming.getCount())); - return stack.copy().shrink(coming.getCount()); - } - } - - @Override - public void setStack(int slot, ItemStack stack) { - inventory.setStack(slot, WrappingUtil.cast(stack, net.minecraft.item.ItemStack.class)); - } -} \ No newline at end of file diff --git a/src/main/resources/META-INF/sandbox-fabric.accesswidener b/src/main/resources/META-INF/sandbox-fabric.accesswidener deleted file mode 100644 index 72e8dc0..0000000 --- a/src/main/resources/META-INF/sandbox-fabric.accesswidener +++ /dev/null @@ -1,7 +0,0 @@ -accessWidener v1 named - -accessible method net/minecraft/client/options/Option getGenericLabel (Lnet/minecraft/text/Text;)Lnet/minecraft/text/Text; -accessible method net/minecraft/client/options/Option getPixelLabel (I)Lnet/minecraft/text/Text; -accessible method net/minecraft/client/options/Option getPercentLabel (D)Lnet/minecraft/text/Text; -accessible method net/minecraft/client/options/Option getPercentAdditionLabel (I)Lnet/minecraft/text/Text; -accessible method net/minecraft/client/options/Option getGenericLabel (I)Lnet/minecraft/text/Text; \ No newline at end of file diff --git a/src/main/resources/META-INF/sandbox.bugfixes.mixins.json b/src/main/resources/META-INF/sandbox.bugfixes.mixins.json deleted file mode 100644 index 5db113b..0000000 --- a/src/main/resources/META-INF/sandbox.bugfixes.mixins.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "required": true, - "package": "org.sandboxpowered.sandbox.fabric.mixin.fixes", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.8", - "mixinPriority": 5480, - "mixins": [ - ] -} diff --git a/src/main/resources/META-INF/sandbox.event.mixins.json b/src/main/resources/META-INF/sandbox.event.mixins.json deleted file mode 100644 index e592e94..0000000 --- a/src/main/resources/META-INF/sandbox.event.mixins.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "required": true, - "package": "org.sandboxpowered.sandbox.fabric.mixin.event", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.8", - "mixinPriority": 5480, - "mixins": [ - "block.MixinAnvilBlock", - "enchant.MixinEnchantment", - "entity.MixinFallingBlockEntity", - "entity.MixinLightningEntity", - "entity.MixinLivingEntity", - "entity.MixinPlayerEntity", - "entity.MixinPlayerInventory", - "entity.MixinServerPlayerEntity", - "item.MixinBlockItem", - "item.MixinItemStack", - "network.MixinServerPlayerInteractionManager", - "world.MixinBlockCollisionSpliterator", - "world.MixinServerWorld" - ], - "client": [ - "client.MixinMinecraftClient", - "client.MixinWorldRenderer", - "network.MixinClientPlayerInteractionManager" - ] -} diff --git a/src/main/resources/META-INF/sandbox.fabric.mixins.json b/src/main/resources/META-INF/sandbox.fabric.mixins.json deleted file mode 100644 index eb09e4d..0000000 --- a/src/main/resources/META-INF/sandbox.fabric.mixins.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "required": true, - "package": "org.sandboxpowered.sandbox.fabric.mixin.fabric", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.8", - "mixinPriority": 5480, - "mixins": [ - "MixinBootstrap", - "block.MixinBlock", - "block.MixinBlock$MixinSettings", - "block.MixinBlockState", - "block.MixinStateManager", - "block.MixinStateManager$MixinStateBuilder", - "crash.MixinCrashReport", - "enchant.MixinEnchantment", - "enchant.MixinEnchantmentHelper", - "networking.MixinCustomPayloadC2SPacket", - "networking.MixinCustomPayloadS2CPacket", - "networking.MixinLoginQueryRequestS2CPacket", - "networking.MixinLoginQueryResponseC2SPacket", - "networking.MixinPlayerManager", - "networking.MixinServerConfigHandler", - "networking.MixinServerLoginNetworkHandler", - "networking.MixinServerPlayNetworkHandler", - "registry.MixinRegistry", - "registry.MixinSimpleRegistry", - "server.MixinMinecraftServer", - "world.MixinServerWorld" - ], - "client": [ - "client.MixinClientBrandRetriever", - "client.MixinGameOptions", - "client.MixinGameRenderer", - "client.MixinIntegratedServer", - "client.MixinKeyboard", - "client.MixinItemGroup", - "client.MixinMinecraftClient", - "client.MixinResourcePackManager", - "client.MixinTitleScreen", - "client.MixinScreen", - "client.MixinVideoOptionsScreen", - "networking.MixinClientConnection", - "networking.MixinClientPlayNetworkHandler" - ], - "server": [ - "server.MixinDedicatedServer" - ] -} diff --git a/src/main/resources/META-INF/sandbox.impl.mixins.json b/src/main/resources/META-INF/sandbox.impl.mixins.json deleted file mode 100644 index f10fc8c..0000000 --- a/src/main/resources/META-INF/sandbox.impl.mixins.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "required": true, - "package": "org.sandboxpowered.sandbox.fabric.mixin.impl", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.8", - "mixinPriority": 5480, - "mixins": [ - "block.MixinAbstractBlock", - "block.MixinBlock", - "block.MixinBlockEntity", - "block.MixinHopperBlockEntity", - "block.MixinMaterial", - "block.MixinSandboxBlock", - "block.MixinWaterlogged", - "block.entity.MixinBlockEntityType", - "enchant.MixinEnchantment", - "enchant.MixinSandboxEnchantment", - "entity.MixinEntity", - "entity.MixinEntityType", - "entity.MixinLivingEntity", - "entity.MixinPlayerEntity", - "entity.MixinServerPlayerEntity", - "fluid.MixinBaseFluid", - "fluid.MixinFluid", - "fluid.MixinFluidState", - "fluid.MixinSandboxFluid", - "item.MixinBlockItem", - "item.MixinItem", - "item.MixinItemStack", - "item.MixinSandboxItem", - "nbt.MixinCompoundTag", - "nbt.MixinTag", - "server.MixinMinecraftServer", - "shape.MixinBox", - "shape.MixinVoxelShape", - "state.MixinBlockState", - "state.MixinState", - "text.MixinText", - "util.MixinBlockPos", - "util.MixinBlockPos$MixinMutable", - "util.MixinIdentifier", - "util.MixinProperty", - "util.MixinVec3d", - "util.MixinVec3i", - "util.MixinVector3f", - "world.MixinBlockView", - "world.MixinModifiableWorld", - "world.MixinWorld" - ], - "client": [ - "block.MixinBlockClient", - "client.MixinFluidRenderer", - "client.MixinMinecraftClient", - "client.MixinModelLoader", - "client.MixinRenderLayers", - "client.MixinWorldRenderer" - ] -} diff --git a/src/main/resources/META-INF/sandbox.performance.mixins.json b/src/main/resources/META-INF/sandbox.performance.mixins.json deleted file mode 100644 index 53166de..0000000 --- a/src/main/resources/META-INF/sandbox.performance.mixins.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "required": false, - "package": "org.sandboxpowered.sandbox.fabric.mixin.performance", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.8", - "mixinPriority": 1, - "mixins": [ - "direction_values.block.MixinAbstractRedstoneGateBlock", - "direction_values.block.MixinConcretePowderBlock", - "direction_values.block.MixinCoralBlockBlock", - "direction_values.block.MixinCoralParentBlock", - "direction_values.block.MixinFireBlock", - "direction_values.block.MixinFluidBlock", - "direction_values.block.MixinFrostedIceBlock", - "direction_values.block.MixinLeavesBlock", - "direction_values.block.MixinPistonBlock", - "direction_values.block.MixinRedstoneOreBlock", - "direction_values.block.MixinRedstoneTorchBlock", - "direction_values.block.MixinRedstoneWireBlock", - "direction_values.block.MixinSpongeBlock", - "direction_values.block.pattern.MixinBlockPattern", - "direction_values.block.piston.MixinPistonHandler", - "direction_values.entity.ai.pathing.MixinAmphibiousPathNodeMarker", - "direction_values.entity.ai.pathing.MixinWaterPathNodeMarker", - "direction_values.entity.mob.MixinShulkerEntity", - "direction_values.fluid.MixinLavaFluid", - "direction_values.math.MixinDirectionTransformation", - "direction_values.property.MixinDirectionProperty", - "direction_values.structure.MixinBuriedTreasureGeneratorPiece", - "direction_values.structure.MixinOceanMonumentGeneratorBase", - "direction_values.world.chunk.MixinUpgradeData", - "direction_values.world.gen.feature.MixinBlueIceFeature", - "direction_values.world.gen.feature.MixinGlowstoneBlobFeature", - "direction_values.world.gen.feature.MixinNoSurfaceOreFeature", - "direction_values.world.gen.feature.MixinTreeFeature" - ], - "client": [ - "direction_values.block.entity.MixinEndGatewayBlockEntity", - "direction_values.render.block.MixinBlockModelRenderer", - "direction_values.render.block.MixinBlockModelRenderer$MixinNeighborOrientation", - "direction_values.render.chunk.MixinBuiltChunk", - "direction_values.render.chunk.MixinChunkOcclusionData", - "direction_values.render.item.MixinItemRenderer", - "direction_values.render.model.MixinBakedQuadFactory", - "direction_values.render.model.MixinBasicBakedModelBuilder", - - "particle_culling.MixinParticleManager", - "particle_culling.MixinClientWorld", - "particle_culling.MixinWorldRenderer" - ] -} diff --git a/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService b/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService deleted file mode 100644 index b888935..0000000 --- a/src/main/resources/META-INF/services/org.sandboxpowered.internal.InternalService +++ /dev/null @@ -1 +0,0 @@ -org.sandboxpowered.sandbox.fabric.impl.InternalServiceFabric \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_0.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_0.png deleted file mode 100644 index 0733c41..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_0.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_1.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_1.png deleted file mode 100644 index 3b15fbc..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_1.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_2.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_2.png deleted file mode 100644 index 51b5dbd..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_2.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_3.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_3.png deleted file mode 100644 index 12e35c1..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_3.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_4.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_4.png deleted file mode 100644 index 3c58746..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_4.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_5.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_5.png deleted file mode 100644 index f223d16..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_0/panorama_5.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_0.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_0.png deleted file mode 100644 index 888cad1..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_0.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_1.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_1.png deleted file mode 100644 index ec57f82..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_1.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_2.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_2.png deleted file mode 100644 index b79725b..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_2.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_3.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_3.png deleted file mode 100644 index 2cf44e0..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_3.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_4.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_4.png deleted file mode 100644 index d5cec87..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_4.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_5.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_5.png deleted file mode 100644 index 3411d32..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_1/panorama_5.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_0.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_0.png deleted file mode 100644 index 127a27a..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_0.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_1.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_1.png deleted file mode 100644 index ac569fc..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_1.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_2.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_2.png deleted file mode 100644 index 285218a..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_2.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_3.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_3.png deleted file mode 100644 index 4baa59b..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_3.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_4.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_4.png deleted file mode 100644 index 10fd284..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_4.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_5.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_5.png deleted file mode 100644 index 7c34f9f..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_2/panorama_5.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_0.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_0.png deleted file mode 100644 index 4bbd602..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_0.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_1.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_1.png deleted file mode 100644 index 9575e00..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_1.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_2.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_2.png deleted file mode 100644 index 5399b1b..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_2.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_3.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_3.png deleted file mode 100644 index 5605247..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_3.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_4.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_4.png deleted file mode 100644 index 5bdc373..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_4.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_5.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_5.png deleted file mode 100644 index 36b5930..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_3/panorama_5.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_0.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_0.png deleted file mode 100644 index a0db2ad..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_0.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_1.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_1.png deleted file mode 100644 index 90f9100..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_1.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_2.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_2.png deleted file mode 100644 index 7f56ec5..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_2.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_3.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_3.png deleted file mode 100644 index bfc9023..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_3.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_4.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_4.png deleted file mode 100644 index f7cdd04..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_4.png and /dev/null differ diff --git a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_5.png b/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_5.png deleted file mode 100644 index d1b1d00..0000000 Binary files a/src/main/resources/assets/minecraft/textures/gui/title/background/panorama_4/panorama_5.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/icon.png b/src/main/resources/assets/sandbox/icon.png deleted file mode 100644 index 5319d43..0000000 Binary files a/src/main/resources/assets/sandbox/icon.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/lang/en_us.json b/src/main/resources/assets/sandbox/lang/en_us.json deleted file mode 100644 index d8fbb43..0000000 --- a/src/main/resources/assets/sandbox/lang/en_us.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "options.sandbox.cullparticles": "Cull Particles", - "options.sandbox.worldborder": "World Border", - "options.sandbox.worldborder.vanilla": "Vanilla", - "options.sandbox.worldborder.lines": "Lines", - "options.sandbox.worldborder.grid": "Grid", - "options.sandbox.worldborder.dots": "Dots" -} \ No newline at end of file diff --git a/src/main/resources/assets/sandbox/textures/gui/logo.png b/src/main/resources/assets/sandbox/textures/gui/logo.png deleted file mode 100644 index 1d33d6a..0000000 Binary files a/src/main/resources/assets/sandbox/textures/gui/logo.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/textures/gui/sandbox.png b/src/main/resources/assets/sandbox/textures/gui/sandbox.png deleted file mode 100644 index 9556d5e..0000000 Binary files a/src/main/resources/assets/sandbox/textures/gui/sandbox.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/textures/misc/dot.png b/src/main/resources/assets/sandbox/textures/misc/dot.png deleted file mode 100644 index bf65ca3..0000000 Binary files a/src/main/resources/assets/sandbox/textures/misc/dot.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/textures/misc/grid.png b/src/main/resources/assets/sandbox/textures/misc/grid.png deleted file mode 100644 index 5d13611..0000000 Binary files a/src/main/resources/assets/sandbox/textures/misc/grid.png and /dev/null differ diff --git a/src/main/resources/assets/sandbox/textures/misc/lines.png b/src/main/resources/assets/sandbox/textures/misc/lines.png deleted file mode 100644 index e40b1cc..0000000 Binary files a/src/main/resources/assets/sandbox/textures/misc/lines.png and /dev/null differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index 67ac69c..0000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "schemaVersion": 1, - "id": "sandbox", - "version": "${version}", - "name": "Sandbox Fabric", - "description": "SandboxAPI implementation for FabricMC", - "authors": [ - "SandboxPowered" - ], - "contact": { - "homepage": "https://sandboxpowered.org", - "sources": "https://github.com/SandboxPowered/Sandbox" - }, - "license": "LGPLv3", - "icon": "assets/sandbox/icon.png", - "environment": "*", - "mixins": [ - "META-INF/sandbox.event.mixins.json", - "META-INF/sandbox.fabric.mixins.json", - "META-INF/sandbox.impl.mixins.json", - "META-INF/sandbox.performance.mixins.json", - "META-INF/sandbox.bugfixes.mixins.json" - ], - "accessWidener": "META-INF/sandbox-fabric.accesswidener", - "depends": { - "fabricloader": ">=0.7.9" - }, - "recommends": { - }, - "suggests": { - }, - "conflicts": { - }, - "breaks": { - } -} \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta deleted file mode 100644 index 8bca7d4..0000000 --- a/src/main/resources/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "pack_format": 5, - "description": "Sandbox Resources" - } -}