create structure-block-shortcut addon

This commit is contained in:
dfsek 2021-12-17 09:48:06 -07:00
parent df0a2f29d1
commit 8ff6c3e65c
5 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-2021 Polyhedral Development
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,7 @@
import com.dfsek.terra.version
version = version("0.1.0")
dependencies {
shadedApi(project(":common:addons:manifest-addon-loader"))
}

View File

@ -0,0 +1,45 @@
package com.dfsek.terra.addons.palette.shortcut.block;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.buffer.items.BufferedBlock;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.WritableWorld;
import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import java.util.Random;
public class SingletonStructure implements Structure {
private final BlockState blockState;
public SingletonStructure(BlockState blockState) {
this.blockState = blockState;
}
@Override
public boolean generate(Vector3 location, WritableWorld world, Chunk chunk, Random random, Rotation rotation) {
world.setBlockState(location, blockState);
return true;
}
@Override
public boolean generate(Buffer buffer, WritableWorld world, Random random, Rotation rotation, int recursions) {
world.setBlockState(buffer.getOrigin(), blockState);
return true;
}
@Override
public boolean generate(Vector3 location, WritableWorld world, Random random, Rotation rotation) {
world.setBlockState(location, blockState);
return true;
}
@Override
public String getID() {
return blockState.getAsString();
}
}

View File

@ -0,0 +1,30 @@
package com.dfsek.terra.addons.palette.shortcut.block;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
public class StructureBlockShortcutAddon implements AddonInitializer {
@Inject
private BaseAddon addon;
@Inject
private Platform platform;
@Override
public void initialize() {
platform.getEventManager()
.getHandler(FunctionalEventHandler.class)
.register(addon, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack()
.registerShortcut(Structure.class, "BLOCK",
(configLoader, input) -> new SingletonStructure(configLoader.loadType(BlockState.class, input))))
.failThrough();
}
}

View File

@ -0,0 +1,12 @@
schema-version: 1
contributors:
- Terra contributors
id: structure-block-shortcut
version: @VERSION@
entrypoints:
- "com.dfsek.terra.addons.palette.shortcut.block.StructureBlockShortcutAddon"
website:
issues: https://github.com/PolyhedralDev/Terra/issues
source: https://github.com/PolyhedralDev/Terra
docs: https://github.com/PolyhedralDev/Terra/wiki
license: MIT License