more fabric stuff

This commit is contained in:
dfsek
2021-02-24 01:33:19 -07:00
parent 83f981111a
commit 5c0482e972
17 changed files with 78 additions and 23 deletions

View File

@@ -33,6 +33,7 @@ public class DamageFunction implements LootFunction {
*/
@Override
public ItemStack apply(ItemStack original, Random r) {
if(!(original instanceof Damageable)) return original;
double itemDurability = (r.nextDouble() * (max - min)) + min;
Damageable damage = (Damageable) original.getItemMeta();
damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability()));

View File

@@ -35,6 +35,8 @@ public class EnchantFunction implements LootFunction {
*/
@Override
public ItemStack apply(ItemStack original, Random r) {
if(original.getItemMeta() == null) return original;
double enchant = (r.nextDouble() * (max - min)) + min;
List<Enchantment> possible = new GlueList<>();
for(Enchantment ench : main.getItemHandle().getEnchantments()) {

View File

@@ -123,6 +123,7 @@ public class StructureScript {
private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) {
try {
return cache.get(location, () -> {
System.out.println("{" + FastMath.floorDiv(location.getBlockX(), 16) + ", " + FastMath.floorDiv(location.getBlockZ(), 16) + "} : " + cache.size() + " : " + location.hashCode());
StructureBuffer buf = new StructureBuffer(location);
buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, 0)));
return buf;

View File

@@ -23,9 +23,11 @@ public class BlockFunction implements Function<Void> {
private final Returnable<Number> x, y, z;
private final Position position;
private final Returnable<Boolean> overwrite;
private final TerraPlugin main;
public BlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Returnable<Boolean> overwrite, TerraPlugin main, Position position) throws ParseException {
this.position = position;
this.main = main;
if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition());
try {
@@ -49,7 +51,7 @@ public class BlockFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation());
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap), main), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
return null;
}

View File

@@ -22,11 +22,11 @@ public class StructureBuffer implements Buffer {
}
public void paste(Chunk chunk) {
bufferedItemMap.forEach(((vector3, item) -> {
Location current = origin.clone().add(vector3);
bufferedItemMap.forEach(((location, item) -> {
Location current = origin.clone().add(location);
if(FastMath.floorDiv(current.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(current.getBlockZ(), 16) != chunk.getZ())
return;
item.paste(origin.clone().add(vector3));
item.paste(current);
}));
}

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.api.structures.structure.buffer.items;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
@@ -7,15 +8,22 @@ import com.dfsek.terra.api.platform.block.BlockData;
public class BufferedBlock implements BufferedItem {
private final BlockData data;
private final boolean overwrite;
private final TerraPlugin main;
public BufferedBlock(BlockData data, boolean overwrite) {
public BufferedBlock(BlockData data, boolean overwrite, TerraPlugin main) {
this.data = data;
this.overwrite = overwrite;
this.main = main;
}
@Override
public void paste(Location origin) {
Block block = origin.getBlock();
if(overwrite || block.isEmpty()) block.setBlockData(data, false);
try {
if(overwrite || block.isEmpty()) block.setBlockData(data, false);
} catch(RuntimeException e) {
main.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
main.getDebugLogger().stack(e);
}
}
}

View File

@@ -42,6 +42,7 @@ public class StructurePopulator implements TerraBlockPopulator {
if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(conf))
continue;
Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed()));
System.out.println("chunk: {" + chunk.getX() + ", " + chunk.getZ() + "}");
conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4)));
}
}

View File

@@ -3,4 +3,4 @@ distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx4096m

View File

@@ -31,7 +31,7 @@ configure<LoomGradleExtension> {
}
tasks.register<RemapJarTask>("remapShadedJar") {
setProperty("input", file("build/libs/fabric-${version}-shaded.jar"))
setProperty("input", file("build/libs/Terra-fabric-${version}-shaded.jar"))
setProperty("addNestedDependencies", false)
setProperty("remapAccessWidener", true)
}

View File

@@ -46,6 +46,7 @@ import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Blocks;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
@@ -286,17 +287,23 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
GeneratorTypeAccessor.getVALUES().add(new GeneratorType("terra") {
@Override
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
ConfigPack pack = registry.get("DEFAULT");
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
}
registry.forEach(pack -> {
System.out.println(pack.getTemplate().getID());
pack.getBiomeRegistry().forEach(b -> System.out.println(b.getID()));
final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) {
@Override
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
}
};
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
GeneratorTypeAccessor.getVALUES().add(generatorType);
});
}
}
@Override
public EventManager getEventManager() {
return eventManager;

View File

@@ -31,7 +31,6 @@ public class FabricInventory implements Inventory {
@Override
public void setItem(int slot, ItemStack newStack) {
System.out.println("item @ " + slot + ": " + newStack.getHandle());
delegate.setStack(slot, FabricAdapter.adapt(newStack));
}
}

View File

@@ -1,10 +1,14 @@
package com.dfsek.terra.fabric.mixin;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Mixin(GeneratorType.class)
public interface GeneratorTypeAccessor {
@@ -12,4 +16,19 @@ public interface GeneratorTypeAccessor {
static List<GeneratorType> getVALUES() {
throw new AssertionError();
}
@Accessor
static Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> getSCREEN_PROVIDERS() {
throw new UnsupportedOperationException();
}
@Mutable
@Accessor
static void setSCREEN_PROVIDERS(Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> SCREEN_PROVIDERS) {
throw new UnsupportedOperationException();
}
@Mutable
@Accessor
void setTranslationKey(Text translationKey);
}

View File

@@ -36,7 +36,6 @@ public class FabricBlockState implements BlockState {
return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess);
} else if(block1 instanceof AbstractChestBlock) {
BlockEntity abstractChestBlock = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
System.out.println("inventory: " + block1);
return new FabricContainer(abstractChestBlock, worldAccess);
}
return null;

View File

@@ -12,6 +12,7 @@ import com.dfsek.terra.fabric.world.handles.chunk.FabricChunk;
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.WorldAccess;
import java.io.File;
@@ -73,13 +74,13 @@ public class FabricWorld implements World, FabricWorldHandle {
@Override
public int hashCode() {
return delegate.generator.hashCode();
return ((ServerWorldAccess) delegate.world).toServerWorld().hashCode();
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof FabricWorld)) return false;
return ((FabricWorld) obj).delegate.generator.equals(delegate.generator);
return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld());
}
@Override

View File

@@ -10,6 +10,7 @@ import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
import com.dfsek.terra.fabric.world.block.FabricBlock;
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.WorldAccess;
import java.io.File;
@@ -81,12 +82,13 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle {
@Override
public int hashCode() {
return handle.worldAccess.hashCode();
return ((ServerWorldAccess) handle.worldAccess).toServerWorld().hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
if(!(obj instanceof FabricSeededWorldAccess)) return false;
return ((ServerWorldAccess) ((FabricSeededWorldAccess) obj).handle.worldAccess).toServerWorld().equals(((ServerWorldAccess) handle.worldAccess).toServerWorld());
}
@Override

View File

@@ -89,4 +89,15 @@ public class FabricWorldAccess implements World, FabricWorldHandle {
public WorldAccess getWorld() {
return delegate;
}
@Override
public int hashCode() {
return ((ServerWorldAccess) delegate).toServerWorld().hashCode();
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof FabricWorldAccess)) return false;
return ((ServerWorldAccess) ((FabricWorldAccess) obj).delegate).toServerWorld().equals(((ServerWorldAccess) delegate).toServerWorld());
}
}

View File

@@ -11,6 +11,7 @@ import com.dfsek.terra.fabric.world.block.FabricBlock;
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.WorldAccess;
import java.io.File;
@@ -71,13 +72,14 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle {
@Override
public int hashCode() {
return delegate.generator.hashCode();
return ((ServerWorldAccess) delegate.chunk).toServerWorld().hashCode();
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof FabricWorldChunkRegion)) return false;
return ((FabricWorldChunkRegion) obj).delegate.generator.equals(delegate.generator);
return super.equals(obj);
//return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld());
}
@Override
@@ -92,7 +94,7 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle {
@Override
public Object getHandle() {
return null;
return delegate;
}
@Override