From fca4c20582a14919b8d2adfc1e1547fb6e70a378 Mon Sep 17 00:00:00 2001 From: Alexandra-Myers Date: Fri, 29 Mar 2024 21:36:09 -0400 Subject: [PATCH] Pandora's Box 2.2.6 Forge - Bug eradication & nearing completion of ruined portal --- .../java/ivorius/pandorasbox/PandorasBox.java | 3 - .../effectcreators/PBECConvertToNether.java | 17 ++- .../pandorasbox/effectcreators/PBECPool.java | 3 +- .../effectcreators/PBECRuinedPortal.java | 24 ++-- .../effects/PBEffectGenConvertToNether.java | 48 ++++--- .../pandorasbox/effects/PBEffectGenPool.java | 2 +- .../effects/PBEffectGenRuinedPortal.java | 132 +++++++++++------- .../effects/PBEffectGenStructure.java | 49 ++++--- .../effects/PBEffectGenTargets.java | 6 +- .../pandorasbox/effects/PBEffectGenerate.java | 27 ++-- .../pandorasbox/effects/PBEffectMulti.java | 42 ++---- .../pandorasbox/effects/PBEffectNormal.java | 27 ++-- .../effects/PBEffectRangeBased.java | 18 +-- .../pandorasbox/effects/PBEffects.java | 35 ++--- .../ivorius/pandorasbox/init/Registry.java | 3 +- .../pandorasbox/math/IvMathHelper.java | 10 +- .../pandorasbox/utils/PBNBTHelper.java | 16 ++- .../pandorasbox/weighted/WeightedBlock.java | 6 +- .../weighted/WeightedSelector.java | 100 +++++-------- 19 files changed, 275 insertions(+), 293 deletions(-) diff --git a/src/main/java/ivorius/pandorasbox/PandorasBox.java b/src/main/java/ivorius/pandorasbox/PandorasBox.java index c4c3336..f357749 100644 --- a/src/main/java/ivorius/pandorasbox/PandorasBox.java +++ b/src/main/java/ivorius/pandorasbox/PandorasBox.java @@ -10,7 +10,6 @@ import ivorius.pandorasbox.client.rendering.effects.PBEffectRendererExplosion; import ivorius.pandorasbox.client.rendering.effects.PBEffectRenderingRegistry; import ivorius.pandorasbox.effects.PBEffectExplode; -import ivorius.pandorasbox.effects.PBEffects; import ivorius.pandorasbox.events.PBEventHandler; import ivorius.pandorasbox.init.Registry; import ivorius.pandorasbox.utils.ArrayListExtensions; @@ -55,8 +54,6 @@ public class PandorasBox { public static ArrayListExtensions saplings; public static ArrayListExtensions pots; public static PBConfig CONFIG; - - public static PBEventHandler fmlEventHandler; public PandorasBox() { // Register the setup method for modloading initConfig(); diff --git a/src/main/java/ivorius/pandorasbox/effectcreators/PBECConvertToNether.java b/src/main/java/ivorius/pandorasbox/effectcreators/PBECConvertToNether.java index 729cf51..1ceb061 100644 --- a/src/main/java/ivorius/pandorasbox/effectcreators/PBECConvertToNether.java +++ b/src/main/java/ivorius/pandorasbox/effectcreators/PBECConvertToNether.java @@ -17,29 +17,28 @@ /** * Created by lukas on 30.03.14. */ -public class PBECConvertToNether implements PBEffectCreator -{ +public class PBECConvertToNether implements PBEffectCreator { public DValue range; + public DValue chanceToDiscardNetherrack; public String biome; - public PBECConvertToNether(DValue range, String biome) - { + public PBECConvertToNether(DValue range, DValue chanceToDiscardNetherrack, String biome) { this.range = range; + this.chanceToDiscardNetherrack = chanceToDiscardNetherrack; this.biome = biome; } @Override - public PBEffect constructEffect(World world, double x, double y, double z, Random random) - { + public PBEffect constructEffect(World world, double x, double y, double z, Random random) { double range = this.range.getValue(random); int time = MathHelper.floor((random.nextDouble() * 7.0 + 3.0) * range); + double discardChance = chanceToDiscardNetherrack.getValue(random); - return new PBEffectGenConvertToNether(time, range, PandorasBoxHelper.getRandomUnifiedSeed(random), biome); + return new PBEffectGenConvertToNether(time, range, discardChance, PandorasBoxHelper.getRandomUnifiedSeed(random), biome); } @Override - public float chanceForMoreEffects(World world, double x, double y, double z, Random random) - { + public float chanceForMoreEffects(World world, double x, double y, double z, Random random) { return 0.1f; } } diff --git a/src/main/java/ivorius/pandorasbox/effectcreators/PBECPool.java b/src/main/java/ivorius/pandorasbox/effectcreators/PBECPool.java index 79c594d..b554426 100644 --- a/src/main/java/ivorius/pandorasbox/effectcreators/PBECPool.java +++ b/src/main/java/ivorius/pandorasbox/effectcreators/PBECPool.java @@ -11,6 +11,7 @@ import ivorius.pandorasbox.random.DValue; import ivorius.pandorasbox.weighted.WeightedBlock; import net.minecraft.block.Block; +import net.minecraft.block.Blocks; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; @@ -37,7 +38,7 @@ public PBEffect constructEffect(World world, double x, double y, double z, Rando double range = this.range.getValue(random); int time = MathHelper.floor((random.nextDouble() * 7.0 + 3.0) * range); - Block platformBlock = PandorasBoxHelper.getRandomBlock(random, platformBlocks); + Block platformBlock = platformBlocks.isEmpty() ? Blocks.AIR : PandorasBoxHelper.getRandomBlock(random, platformBlocks); return new PBEffectGenPool(time, range, PandorasBoxHelper.getRandomUnifiedSeed(random), block, platformBlock); } diff --git a/src/main/java/ivorius/pandorasbox/effectcreators/PBECRuinedPortal.java b/src/main/java/ivorius/pandorasbox/effectcreators/PBECRuinedPortal.java index ae150a0..9e6470a 100644 --- a/src/main/java/ivorius/pandorasbox/effectcreators/PBECRuinedPortal.java +++ b/src/main/java/ivorius/pandorasbox/effectcreators/PBECRuinedPortal.java @@ -17,45 +17,41 @@ import net.minecraft.util.Direction; import net.minecraft.world.World; -import java.util.Collection; +import java.util.Arrays; import java.util.Random; /** * Created by lukas on 30.03.14. */ public class PBECRuinedPortal implements PBEffectCreator { - public IValue rangeX; + public IValue rangeH; public IValue rangeY; - public IValue rangeZ; public IValue rangeStartY; public Block block; - public final Collection> bricks; + public final WeightedBlock[][] bricks; public final ArrayListExtensions loot; - public final Direction.Axis axis; - public PBECRuinedPortal(IValue rangeX, IValue rangeY, IValue rangeZ, IValue rangeStartY, Collection> brickSet, ArrayListExtensions loot, Direction.Axis axis) { - this.rangeX = rangeX; + public PBECRuinedPortal(IValue rangeH, IValue rangeY, IValue rangeStartY, WeightedBlock[][] brickSet, ArrayListExtensions loot) { + this.rangeH = rangeH; this.rangeY = rangeY; - this.rangeZ = rangeZ; this.rangeStartY = rangeStartY; this.bricks = brickSet; this.loot = loot; - this.axis = axis; } @Override public PBEffect constructEffect(World world, double x, double y, double z, Random random) { - int rangeX = this.rangeX.getValue(random); + int rangeH = this.rangeH.getValue(random); int rangeY = this.rangeY.getValue(random); int rangeStartY = this.rangeStartY.getValue(random); - int rangeZ = this.rangeZ.getValue(random); rangeY += rangeStartY; - int time = 6 * (rangeX * rangeY * rangeZ) + 50; + int time = rangeH * rangeH * rangeY; - ArrayListExtensions bricks = WeightedSelector.selectWeightless(random, this.bricks, this.bricks.size()); + WeightedBlock[] bricks = WeightedSelector.selectWeightless(random, Arrays.asList(this.bricks), this.bricks.length); + Direction.Axis axis = random.nextBoolean() ? Direction.Axis.X : Direction.Axis.Z; - return new PBEffectGenRuinedPortal(time, rangeX, rangeZ, rangeY, rangeStartY, PandorasBoxHelper.getRandomUnifiedSeed(random), bricks, loot, axis); + return new PBEffectGenRuinedPortal(time, rangeH, rangeY, rangeStartY, PandorasBoxHelper.getRandomUnifiedSeed(random), bricks, loot, axis); } @Override diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenConvertToNether.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenConvertToNether.java index 9e22e42..45d6a67 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenConvertToNether.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenConvertToNether.java @@ -31,44 +31,47 @@ */ public class PBEffectGenConvertToNether extends PBEffectGenerate { private String biome; + private double discardNetherrackChance; private int timesFeatureAMade = 0; private int timesFeatureBMade = 0; public PBEffectGenConvertToNether() {} - public PBEffectGenConvertToNether(int time, double range, int unifiedSeed, String biome) { + public PBEffectGenConvertToNether(int time, double range, double discardChance, int unifiedSeed, String biome) { super(time, range, 2, unifiedSeed); + this.discardNetherrackChance = discardChance; this.biome = biome; } @Override public void generateOnBlock(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, int pass, BlockPos pos, double range) { - if(world instanceof ServerWorld) { + if (world instanceof ServerWorld) { ServerWorld serverWorld = (ServerWorld) world; + float newRatio = getRatioDone(entity.getEffectTicksExisted() + 1); switch (biome) { case "wastes": { - createWastes(serverWorld, entity, random, pass, pos); + createWastes(serverWorld, entity, random, pass, newRatio, pos); break; } case "soul_sand_valley": { - createSoul(serverWorld, entity, random, pass, pos); + createSoul(serverWorld, entity, random, pass, newRatio, pos); break; } case "crimson": { - createCrimson(serverWorld, entity, random, pass, pos); + createCrimson(serverWorld, entity, random, pass, newRatio, pos); break; } case "warped": { - createWarped(serverWorld, entity, random, pass, pos); + createWarped(serverWorld, entity, random, pass, newRatio, pos); break; } case "deltas": { - createDeltas(serverWorld, entity, random, pass, pos); + createDeltas(serverWorld, entity, random, pass, newRatio, pos); break; } } } } - public void createWastes(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, BlockPos pos) { + public void createWastes(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, float newRatio, BlockPos pos) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); ArrayListExtensions blocks = new ArrayListExtensions<>(); @@ -79,7 +82,9 @@ public void createWastes(ServerWorld world, PandorasBoxEntity entity, Random ran misc.addAll(PandorasBox.terracotta); if (pass == 0) { - if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { + if (random.nextDouble() < (discardNetherrackChance / 100) * Math.pow(1 + (discardNetherrackChance * 2), newRatio * 100)) { + return; + } else if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { Optional integer = blockState.getOptionalValue(FlowingFluidBlock.LEVEL); BlockState blockState2 = Blocks.LAVA.defaultBlockState(); if(integer.isPresent()) { @@ -140,7 +145,7 @@ public void createWastes(ServerWorld world, PandorasBoxEntity entity, Random ran if(success) timesFeatureAMade++; } } - if(random.nextDouble() < Math.pow(0.3, Math.floor(timesFeatureBMade / 4.0))) { + if (random.nextDouble() < Math.pow(0.3, Math.floor(timesFeatureBMade / 4.0))) { BlockPos posBelow = pos.below(); BlockState blockBelowState = world.getBlockState(posBelow); @@ -150,7 +155,7 @@ public void createWastes(ServerWorld world, PandorasBoxEntity entity, Random ran } } } - public void createSoul(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, BlockPos pos) { + public void createSoul(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, float newRatio, BlockPos pos) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); ArrayListExtensions blocks = new ArrayListExtensions<>(); @@ -161,6 +166,7 @@ public void createSoul(ServerWorld world, PandorasBoxEntity entity, Random rando misc.addAll(PandorasBox.terracotta); if (pass == 0) { + if (random.nextDouble() < (discardNetherrackChance / 100) * Math.pow(1 + (discardNetherrackChance * 2), newRatio * 100)) return; if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { Optional integer = blockState.getOptionalValue(FlowingFluidBlock.LEVEL); BlockState blockState2 = Blocks.LAVA.defaultBlockState(); @@ -215,7 +221,7 @@ public void createSoul(ServerWorld world, PandorasBoxEntity entity, Random rando } } } - public void createCrimson(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, BlockPos pos) { + public void createCrimson(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, float newRatio, BlockPos pos) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); ArrayListExtensions blocks = new ArrayListExtensions<>(); @@ -229,7 +235,9 @@ public void createCrimson(ServerWorld world, PandorasBoxEntity entity, Random ra blocks.removeAll(Blocks.CRIMSON_STEM, Blocks.STRIPPED_CRIMSON_STEM, Blocks.WARPED_STEM, Blocks.STRIPPED_WARPED_STEM); if (pass == 0) { - if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { + if (random.nextDouble() < (discardNetherrackChance / 100) * Math.pow(1 + (discardNetherrackChance * 2), newRatio * 100)) { + return; + } else if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { Optional integer = blockState.getOptionalValue(FlowingFluidBlock.LEVEL); BlockState blockState2 = Blocks.LAVA.defaultBlockState(); if(integer.isPresent()) { @@ -307,7 +315,7 @@ public void createCrimson(ServerWorld world, PandorasBoxEntity entity, Random ra } } } - public void createWarped(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, BlockPos pos) { + public void createWarped(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, float newRatio, BlockPos pos) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); ArrayListExtensions blocks = new ArrayListExtensions<>(); @@ -321,7 +329,9 @@ public void createWarped(ServerWorld world, PandorasBoxEntity entity, Random ran blocks.removeAll(Blocks.CRIMSON_STEM, Blocks.STRIPPED_CRIMSON_STEM, Blocks.WARPED_STEM, Blocks.STRIPPED_WARPED_STEM); if (pass == 0) { - if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { + if (random.nextDouble() < (discardNetherrackChance / 100) * Math.pow(1 + (discardNetherrackChance * 2), newRatio * 100)) { + return; + } else if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { Optional integer = blockState.getOptionalValue(FlowingFluidBlock.LEVEL); BlockState blockState2 = Blocks.LAVA.defaultBlockState(); if(integer.isPresent()) { @@ -392,7 +402,7 @@ public void createWarped(ServerWorld world, PandorasBoxEntity entity, Random ran } } } - public void createDeltas(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, BlockPos pos) { + public void createDeltas(ServerWorld world, PandorasBoxEntity entity, Random random, int pass, float newRatio, BlockPos pos) { BlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); ArrayListExtensions blocks = new ArrayListExtensions<>(); @@ -403,7 +413,9 @@ public void createDeltas(ServerWorld world, PandorasBoxEntity entity, Random ran misc.addAll(PandorasBox.terracotta); if (pass == 0) { - if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { + if (random.nextDouble() < (discardNetherrackChance / 100) * Math.pow(1 + (discardNetherrackChance * 2), newRatio * 100)) { + return; + } else if (isBlockAnyOf(block, Blocks.COBBLESTONE, Blocks.ICE, Blocks.WATER, Blocks.OBSIDIAN)) { Optional integer = blockState.getOptionalValue(FlowingFluidBlock.LEVEL); BlockState blockState2 = Blocks.LAVA.defaultBlockState(); if(integer.isPresent()) { @@ -479,6 +491,7 @@ private void createGlowstoneBlobs(ServerWorld world, BlockPos pos, Random random public void readFromNBT(CompoundNBT compound) { super.readFromNBT(compound); biome = compound.getString("biome"); + discardNetherrackChance = compound.getDouble("discardNetherrackChance"); timesFeatureAMade = compound.getInt("featureACount"); timesFeatureBMade = compound.getInt("featureBCount"); } @@ -489,6 +502,7 @@ public void writeToNBT(CompoundNBT compound) { if (biome != null) { compound.putString("biome", biome); } + compound.putDouble("discardNetherrackChance", discardNetherrackChance); compound.putInt("featureACount", timesFeatureAMade); compound.putInt("featureBCount", timesFeatureBMade); } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenPool.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenPool.java index 861657f..cb387af 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenPool.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenPool.java @@ -35,7 +35,7 @@ public PBEffectGenPool(int time, double range, int unifiedSeed, Block block, Blo public void generateOnBlock(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, int pass, BlockPos pos, double range) { if (!world.isClientSide && !world.getBlockState(pos).isAir()) { boolean setPlatform = false; - if (platformBlock != null) { + if (platformBlock != null && !platformBlock.defaultBlockState().isAir()) { List livingEntities = world.getEntitiesOfClass(LivingEntity.class, BlockPositions.expandToAABB(pos, 2.5, 2.5, 2.5)); if (!livingEntities.isEmpty()) diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenRuinedPortal.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenRuinedPortal.java index 31f95f8..3a0f053 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenRuinedPortal.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenRuinedPortal.java @@ -6,75 +6,73 @@ import ivorius.pandorasbox.utils.PBNBTHelper; import ivorius.pandorasbox.utils.RandomizedItemStack; import ivorius.pandorasbox.weighted.WeightedBlock; -import net.minecraft.block.Blocks; +import ivorius.pandorasbox.weighted.WeightedSelector; +import net.minecraft.block.*; import net.minecraft.nbt.CompoundNBT; +import net.minecraft.state.properties.Half; +import net.minecraft.state.properties.SlabType; +import net.minecraft.tags.FluidTags; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import java.util.Arrays; import java.util.Collections; +import java.util.Objects; import java.util.Random; public class PBEffectGenRuinedPortal extends PBEffectGenStructure { - public ArrayListExtensions bricks = new ArrayListExtensions<>(); + public WeightedBlock[] bricks = new WeightedBlock[]{}; public ArrayListExtensions loot = new ArrayListExtensions<>(); public Direction.Axis axis = Direction.Axis.X; + public boolean[] usedStairsForTop = new boolean[2]; public PBEffectGenRuinedPortal() {} - public PBEffectGenRuinedPortal(int time, int maxX, int maxZ, int maxY, int startY, int unifiedSeed, ArrayListExtensions brickSet, ArrayListExtensions loot, Direction.Axis axis) { - super(time, maxX, maxZ, maxY, startY, unifiedSeed); + public PBEffectGenRuinedPortal(int time, int maxH, int maxY, int startY, int unifiedSeed, WeightedBlock[] brickSet, ArrayListExtensions loot, Direction.Axis axis) { + super(time, maxH, maxH, maxY, startY, unifiedSeed); this.bricks = brickSet; this.loot = loot; this.axis = axis; } @Override - public void buildStructure(World world, PandorasBoxEntity entity, BlockPos currentPos, Random random, float prevRatio, float newRatio, int length, int width, int height, int originY, int originX, int originZ) { + public boolean buildStructure(World world, PandorasBoxEntity entity, BlockPos currentPos, Random random, float prevRatio, float newRatio, int length, int width, int height, int originY, int originX, int originZ) { + height -= 1; int relativeHeight = currentPos.getY() - originY; double relative = (double) relativeHeight / height; - boolean bl = MathHelper.ceil(length * 0.5) >= 2; - boolean bl1 = MathHelper.ceil(width * 0.5) >= 2; - int portalXAxis = bl ? MathHelper.ceil(length * 0.5) : 2; - int portalZAxis = bl1 ? MathHelper.ceil(width * 0.5) : 2; - if ((currentPos.getY() == originY || relative == Math.ceil(relative)) && IvMathHelper.isBetween(currentPos.getX(), originX, portalXAxis) && axis == Direction.Axis.X && currentPos.getZ() == originZ) { - if (random.nextDouble() > 0.15) { - if(random.nextDouble() > 0.75) { - setBlockSafe(world, currentPos, Blocks.CRYING_OBSIDIAN.defaultBlockState()); - } else { - setBlockSafe(world, currentPos, Blocks.OBSIDIAN.defaultBlockState()); + int portalHAxis = Math.max(MathHelper.ceil(length * 0.5), 2); + int currentH = currentPos.getX(); + int originH = originX; + int currentOH = currentPos.getZ(); + int originOH = originZ; + if (Objects.requireNonNull(axis) == Direction.Axis.Z) { + currentH = currentPos.getZ(); + originH = originZ; + currentOH = currentPos.getX(); + originOH = originX; + } + if (currentOH == originOH) { + if ((currentPos.getY() == originY || relative == Math.ceil(relative)) && IvMathHelper.isBetweenInclusive(currentH, originH, portalHAxis)) { + return portalEdges(world, currentPos, random); + } else if (currentPos.getY() == originY + height + 1 && IvMathHelper.isBetweenInclusive(currentH, originH, portalHAxis + 1)) { + return portalTop(world, currentPos, random, originX, originZ, currentH - originH); + } else if (IvMathHelper.isBetweenInclusive(currentPos.getY(), MathHelper.floor(originY + height * 0.5), MathHelper.ceil(height * 0.5)) && IvMathHelper.compareOffsets(currentH, originH, portalHAxis)) { + return portalEdges(world, currentPos, random); + } else if (IvMathHelper.isBetweenInclusive(currentPos.getY(), MathHelper.floor(originY + height * 0.5), MathHelper.ceil(height * 0.5)) && IvMathHelper.compareOffsets(currentH, originH, portalHAxis + 1)) { + if (random.nextDouble() > 0.25) { + Block block = WeightedSelector.selectItem(random, Arrays.asList(bricks)).block; + setBlockSafe(world, currentPos, block instanceof StairsBlock ? block.defaultBlockState().setValue(StairsBlock.HALF, random.nextBoolean() ? Half.TOP : Half.BOTTOM) : block instanceof SlabBlock ? block.defaultBlockState().setValue(SlabBlock.TYPE, SlabType.values()[world.random.nextInt(SlabType.values().length - 1)]) : block.defaultBlockState()); + return true; } - } else - setBlockToAirSafe(world, currentPos); - } else if ((currentPos.getY() == originY || relative == Math.ceil(relative)) && IvMathHelper.isBetween(currentPos.getZ(), originZ, portalZAxis) && axis == Direction.Axis.Z && currentPos.getX() == originX) { - if (random.nextDouble() > 0.15) { - if(random.nextDouble() > 0.75) { - setBlockSafe(world, currentPos, Blocks.CRYING_OBSIDIAN.defaultBlockState()); - } else { - setBlockSafe(world, currentPos, Blocks.OBSIDIAN.defaultBlockState()); - } - } else - setBlockToAirSafe(world, currentPos); - } else if (IvMathHelper.isBetween(currentPos.getY(), MathHelper.floor(originY + height * 0.5), MathHelper.ceil(height * 0.5)) && IvMathHelper.compareOffsets(currentPos.getX(), originX, portalXAxis) && axis == Direction.Axis.X && currentPos.getZ() == originZ) { - if (random.nextDouble() > 0.15) { - if(random.nextDouble() > 0.75) { - setBlockSafe(world, currentPos, Blocks.CRYING_OBSIDIAN.defaultBlockState()); - } else { - setBlockSafe(world, currentPos, Blocks.OBSIDIAN.defaultBlockState()); - } - } else - setBlockToAirSafe(world, currentPos); - } else if (IvMathHelper.isBetween(currentPos.getY(), MathHelper.floor(originY + height * 0.5), MathHelper.ceil(height * 0.5)) && IvMathHelper.compareOffsets(currentPos.getZ(), originZ, portalZAxis) && axis == Direction.Axis.Z && currentPos.getX() == originX) { - if (random.nextDouble() > 0.15) { - if(random.nextDouble() > 0.75) { - setBlockSafe(world, currentPos, Blocks.CRYING_OBSIDIAN.defaultBlockState()); - } else { - setBlockSafe(world, currentPos, Blocks.OBSIDIAN.defaultBlockState()); - } - } else - setBlockToAirSafe(world, currentPos); - } else - setBlockToAirSafe(world, currentPos); + } + } else if (currentPos.getY() == originY && IvMathHelper.isBetweenInclusive(currentH, originH, 2) && world.getBlockState(currentPos).getFluidState().is(FluidTags.LAVA)) { + if (random.nextDouble() > 0.25) { + setBlockSafe(world, currentPos, bricks[3].block.defaultBlockState()); + return true; + } + } + return false; } @Override @@ -82,7 +80,7 @@ public void writeToNBT(CompoundNBT compound) { super.writeToNBT(compound); compound.putString("axis", axis == Direction.Axis.X ? "x" : "z"); PBNBTHelper.writeNBTRandomizedStacks("loot", loot.toArray(new RandomizedItemStack[]{}), compound); - PBNBTHelper.writeNBTWeightedBlocks("bricks", bricks.toArray(new WeightedBlock[]{}), compound); + PBNBTHelper.writeNBTWeightedBlocks("bricks", bricks, compound); } @Override @@ -94,8 +92,42 @@ public void readFromNBT(CompoundNBT compound) { loot = new ArrayListExtensions<>(randomizedItemStacks.length); Collections.addAll(loot, randomizedItemStacks); - WeightedBlock[] bricks = PBNBTHelper.readNBTWeightedBlocks("bricks", compound); - this.bricks = new ArrayListExtensions<>(bricks.length); - Collections.addAll(this.bricks, bricks); + this.bricks = PBNBTHelper.readNBTWeightedBlocks("bricks", compound); + } + + public static boolean portalEdges(World world, BlockPos currentPos, Random random) { + if (random.nextDouble() > 0.25) { + if (random.nextDouble() > 0.75) + setBlockSafe(world, currentPos, Blocks.CRYING_OBSIDIAN.defaultBlockState()); + else + setBlockSafe(world, currentPos, Blocks.OBSIDIAN.defaultBlockState()); + return true; + } + return false; + } + public boolean portalTop(World world, BlockPos currentPos, Random random, int originX, int originZ, int diff) { + if (currentPos.getX() == originX && currentPos.getZ() == originZ) { + if (random.nextDouble() > 0.25) { + setBlockSafe(world, currentPos, Blocks.GOLD_BLOCK.defaultBlockState()); + return true; + } + } else if (random.nextDouble() > 0.25) { + boolean isNegative = diff < 0; + Block block = WeightedSelector.selectItem(random, Arrays.asList(bricks)).block; + BlockState state = block.defaultBlockState(); + if (block instanceof StairsBlock) { + state = state.setValue(StairsBlock.FACING, Direction.fromAxisAndDirection(axis, isNegative ? Direction.AxisDirection.POSITIVE : Direction.AxisDirection.NEGATIVE)); + if (isNegative ? usedStairsForTop[0] : usedStairsForTop[1]) + state = bricks[3].block.defaultBlockState(); + if (isNegative) + usedStairsForTop[0] = true; + else + usedStairsForTop[1] = true; + } else if (!(block instanceof SlabBlock) && random.nextBoolean()) + state = bricks[3].block.defaultBlockState(); + setBlockSafe(world, currentPos, state); + return true; + } + return false; } } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenStructure.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenStructure.java index d872ec6..739623d 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenStructure.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenStructure.java @@ -36,14 +36,17 @@ public PBEffectGenStructure(int maxTicksAlive, int maxX, int maxZ, int maxY, int this.grounded = grounded; this.unifiedSeed = unifiedSeed; } + @Override public void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, float prevRatio, float newRatio) { - if(world.isClientSide()) return; - world.getBlockState(blockPos); - if(!hasAlreadyStarted) { + if (world.isClientSide()) return; + boolean bl = false; + if (!hasAlreadyStarted) { blockPos.set(effectCenter.x, effectCenter.y, effectCenter.z); + int originY = blockPos.getY(); BlockState state = world.getBlockState(blockPos); - if(grounded) { + blockPos.move(0, -startingYOffset, 0); + if (grounded) { while (state.isAir()) { blockPos.move(0, -1, 0); state = world.getBlockState(blockPos); @@ -52,31 +55,36 @@ public void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, blockPos.move(0, 1, 0); } } - blockPos.move(0, -startingYOffset, 0); x = blockPos.getX() - length; y = blockPos.getY(); z = blockPos.getZ() - width; + startingYOffset = originY - y; hasAlreadyStarted = true; } - if (y <= blockPos.getY() + height) { - if (x <= blockPos.getX() + length) { - if (z <= blockPos.getZ() + width) { - buildStructure(world, entity, new BlockPos(x, y, z), random, prevRatio, newRatio, length, width, height, blockPos.getY(), blockPos.getX(), blockPos.getZ()); - z++; + int i = 0; + while (!bl) { + i++; + if (i >= 40) + break; + if (y <= blockPos.getY() + height) { + if (x <= blockPos.getX() + length) { + if (z <= blockPos.getZ() + width) { + bl = buildStructure(world, entity, new BlockPos(x, y, z), random, prevRatio, newRatio, length, width, height, blockPos.getY(), blockPos.getX(), blockPos.getZ()); + z++; + } else { + z = blockPos.getZ() - width; + x++; + } } else { - z = blockPos.getZ() - width; - x++; + x = blockPos.getX() - length; + y++; } - } else { - x = blockPos.getX() - length; - y++; - } + } else break; } } - public abstract void buildStructure(World world, PandorasBoxEntity entity, BlockPos currentPos, Random random, float prevRatio, float newRatio, int length, int width, int height, int originY, int originX, int originZ); + public abstract boolean buildStructure(World world, PandorasBoxEntity entity, BlockPos currentPos, Random random, float prevRatio, float newRatio, int length, int width, int height, int originY, int originX, int originZ); @Override - public void writeToNBT(CompoundNBT compound) - { + public void writeToNBT(CompoundNBT compound) { super.writeToNBT(compound); compound.putInt("length", length); @@ -94,8 +102,7 @@ public void writeToNBT(CompoundNBT compound) } @Override - public void readFromNBT(CompoundNBT compound) - { + public void readFromNBT(CompoundNBT compound) { super.readFromNBT(compound); length = compound.getInt("length"); diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenTargets.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenTargets.java index 58f4c48..e076612 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenTargets.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenTargets.java @@ -52,8 +52,7 @@ public void createTargets(World world, double x, double y, double z, Random rand structureTarget.structureLength = 0.5f + random.nextFloat() * 0.2f; structureTarget.colors = new int[MathHelper.ceil(targetSize) * 2]; - for (int j = 0; j < structureTarget.colors.length; j++) - { + for (int j = 0; j < structureTarget.colors.length; j++) { structureTarget.colors[j] = random.nextInt(16); } @@ -124,8 +123,7 @@ public void readFromNBT(CompoundNBT compound) { } @Override - public StructureTarget createStructure() - { + public StructureTarget createStructure() { return new StructureTarget(); } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenerate.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenerate.java index 3592d78..2e05c0d 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectGenerate.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectGenerate.java @@ -16,37 +16,30 @@ /** * Created by lukas on 30.03.14. */ -public abstract class PBEffectGenerate extends PBEffectRangeBased -{ +public abstract class PBEffectGenerate extends PBEffectRangeBased { public int unifiedSeed; public PBEffectGenerate() {} - public PBEffectGenerate(int time, double range, int passes, int unifiedSeed) - { + public PBEffectGenerate(int time, double range, int passes, int unifiedSeed) { super(time, range, passes); this.unifiedSeed = unifiedSeed; } @Override - public void generateInRange(World world, PandorasBoxEntity entity, Random random, Vec3d effectCenter, double prevRange, double newRange, int pass) - { + public void generateInRange(World world, PandorasBoxEntity entity, Random random, Vec3d effectCenter, double prevRange, double newRange, int pass) { int requiredRange = MathHelper.ceil(newRange); int baseX = MathHelper.floor(effectCenter.x); int baseY = MathHelper.floor(effectCenter.y); int baseZ = MathHelper.floor(effectCenter.z); - for (int x = -requiredRange; x <= requiredRange; x++) - { - for (int y = -requiredRange; y <= requiredRange; y++) - { - for (int z = -requiredRange; z <= requiredRange; z++) - { + for (int x = -requiredRange; x <= requiredRange; x++) { + for (int y = -requiredRange; y <= requiredRange; y++) { + for (int z = -requiredRange; z <= requiredRange; z++) { double dist = MathHelper.sqrt(x * x + y * y + z * z); - if (dist <= newRange) - { + if (dist <= newRange) { if (dist > prevRange) generateOnBlock(world, entity, effectCenter, random, pass, new BlockPos(baseX + x, baseY + y, baseZ + z), dist); else @@ -60,15 +53,13 @@ public void generateInRange(World world, PandorasBoxEntity entity, Random random public abstract void generateOnBlock(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, int pass, BlockPos pos, double range); @Override - public void writeToNBT(CompoundNBT compound) - { + public void writeToNBT(CompoundNBT compound) { super.writeToNBT(compound); compound.putInt("unifiedSeed", unifiedSeed); } @Override - public void readFromNBT(CompoundNBT compound) - { + public void readFromNBT(CompoundNBT compound) { super.readFromNBT(compound); unifiedSeed = compound.getInt("unifiedSeed"); } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectMulti.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectMulti.java index 5c11ec5..0dbc1bf 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectMulti.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectMulti.java @@ -13,38 +13,31 @@ /** * Created by lukas on 31.03.14. */ -public class PBEffectMulti extends PBEffect -{ +public class PBEffectMulti extends PBEffect { public PBEffect[] effects; public int[] delays; public PBEffectMulti() { } - public PBEffectMulti(PBEffect[] effects, int[] delays) - { + public PBEffectMulti(PBEffect[] effects, int[] delays) { this.effects = effects; this.delays = delays; } @Override - public void doTick(PandorasBoxEntity entity, Vec3d effectCenter, int ticksAlive) - { - for (int i = 0; i < effects.length; i++) - { + public void doTick(PandorasBoxEntity entity, Vec3d effectCenter, int ticksAlive) { + for (int i = 0; i < effects.length; i++) { int effectTicks = ticksAlive - delays[i]; effects[i].doTick(entity, effectCenter, effectTicks); } } @Override - public boolean isDone(PandorasBoxEntity entity, int ticksAlive) - { - for (int i = 0; i < effects.length; i++) - { + public boolean isDone(PandorasBoxEntity entity, int ticksAlive) { + for (int i = 0; i < effects.length; i++) { int effectTicks = ticksAlive - delays[i]; - if (!effects[i].isDone(entity, effectTicks)) - { + if (!effects[i].isDone(entity, effectTicks)) { return false; } } @@ -53,12 +46,10 @@ public boolean isDone(PandorasBoxEntity entity, int ticksAlive) } @Override - public void writeToNBT(CompoundNBT compound) - { + public void writeToNBT(CompoundNBT compound) { ListNBT list = new ListNBT(); - for (int i = 0; i < effects.length; i++) - { + for (int i = 0; i < effects.length; i++) { CompoundNBT cmp = new CompoundNBT(); cmp.putInt("delay", delays[i]); @@ -75,15 +66,13 @@ public void writeToNBT(CompoundNBT compound) } @Override - public void readFromNBT(CompoundNBT compound) - { + public void readFromNBT(CompoundNBT compound) { ListNBT list = compound.getList("effects", Constants.NBT.TAG_COMPOUND); effects = new PBEffect[list.size()]; delays = new int[effects.length]; - for (int i = 0; i < effects.length; i++) - { + for (int i = 0; i < effects.length; i++) { CompoundNBT cmp = list.getCompound(i); delays[i] = cmp.getInt("delay"); @@ -92,12 +81,9 @@ public void readFromNBT(CompoundNBT compound) } @Override - public boolean canGenerateMoreEffectsAfterwards(PandorasBoxEntity entity) - { - for (PBEffect effect : effects) - { - if (!effect.canGenerateMoreEffectsAfterwards(entity)) - { + public boolean canGenerateMoreEffectsAfterwards(PandorasBoxEntity entity) { + for (PBEffect effect : effects) { + if (!effect.canGenerateMoreEffectsAfterwards(entity)) { return false; } } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectNormal.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectNormal.java index a860534..2e06347 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectNormal.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectNormal.java @@ -24,10 +24,8 @@ public PBEffectNormal(int maxTicksAlive) this.maxTicksAlive = maxTicksAlive; } - public float getRatioDone(int ticks) - { - if (ticks == maxTicksAlive) // Make sure value is exact - { + public float getRatioDone(int ticks) { + if (ticks == maxTicksAlive) { // Make sure value is exact return 1.0f; } @@ -36,17 +34,14 @@ public float getRatioDone(int ticks) public abstract void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, float prevRatio, float newRatio); - public void setUpEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random) - { + public void setUpEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random) { } - public void finalizeEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random) - { + public void finalizeEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random) { } @Override - public void doTick(PandorasBoxEntity entity, Vec3d effectCenter, int ticksAlive) - { + public void doTick(PandorasBoxEntity entity, Vec3d effectCenter, int ticksAlive) { float prevRatio = getRatioDone(ticksAlive); float newRatio = getRatioDone(ticksAlive + 1); @@ -61,26 +56,22 @@ public void doTick(PandorasBoxEntity entity, Vec3d effectCenter, int ticksAlive) } @Override - public boolean isDone(PandorasBoxEntity entity, int ticksAlive) - { + public boolean isDone(PandorasBoxEntity entity, int ticksAlive) { return ticksAlive >= maxTicksAlive; } @Override - public void writeToNBT(CompoundNBT compound) - { + public void writeToNBT(CompoundNBT compound) { compound.putInt("maxTicksAlive", maxTicksAlive); } @Override - public void readFromNBT(CompoundNBT compound) - { + public void readFromNBT(CompoundNBT compound) { maxTicksAlive = compound.getInt("maxTicksAlive"); } @Override - public boolean canGenerateMoreEffectsAfterwards(PandorasBoxEntity entity) - { + public boolean canGenerateMoreEffectsAfterwards(PandorasBoxEntity entity) { return true; } } diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffectRangeBased.java b/src/main/java/ivorius/pandorasbox/effects/PBEffectRangeBased.java index 7208301..0d4d70e 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffectRangeBased.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffectRangeBased.java @@ -25,18 +25,15 @@ public PBEffectRangeBased() {} public boolean spreadSquared = true; public boolean easeInOut = true; - public PBEffectRangeBased(int maxTicksAlive, double range, int passes) - { + public PBEffectRangeBased(int maxTicksAlive, double range, int passes) { super(maxTicksAlive); this.range = range; this.passes = passes; } @Override - public void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, float prevRatio, float newRatio) - { - for (int i = 0; i < passes; i++) - { + public void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, Random random, float prevRatio, float newRatio) { + for (int i = 0; i < passes; i++) { double prevRange = getRange(prevRatio, i); double newRange = getRange(newRatio, i); @@ -44,8 +41,7 @@ public void doEffect(World world, PandorasBoxEntity entity, Vec3d effectCenter, } } - private double getRange(double ratio, int pass) - { + protected double getRange(double ratio, int pass) { if (spreadSquared) ratio = Math.sqrt(ratio); if (easeInOut) @@ -60,8 +56,7 @@ private double getRange(double ratio, int pass) public abstract void generateInRange(World world, PandorasBoxEntity entity, Random random, Vec3d effectCenter, double prevRange, double newRange, int pass); @Override - public void writeToNBT(CompoundNBT compound) - { + public void writeToNBT(CompoundNBT compound) { super.writeToNBT(compound); compound.putDouble("range", range); @@ -71,8 +66,7 @@ public void writeToNBT(CompoundNBT compound) } @Override - public void readFromNBT(CompoundNBT compound) - { + public void readFromNBT(CompoundNBT compound) { super.readFromNBT(compound); range = compound.getDouble("range"); diff --git a/src/main/java/ivorius/pandorasbox/effects/PBEffects.java b/src/main/java/ivorius/pandorasbox/effects/PBEffects.java index a90f995..f3cb988 100644 --- a/src/main/java/ivorius/pandorasbox/effects/PBEffects.java +++ b/src/main/java/ivorius/pandorasbox/effects/PBEffects.java @@ -37,17 +37,20 @@ public static void registerEffectCreators() { PBECRegistry.register(new PBECMulti(new PBECSpawnManySameItems(new ILinear(10, 30), PandorasBoxHelper.blocksAndItems), 0, new PBECSpawnTNT(new ILinear(20, 60), new ILinear(1, 10), new ILinear(20, 60), new ValueThrow(new DLinear(0.2, 0.5), new DLinear(0.3, 0.5)), new ValueSpawn(new DLinear(3.0, 10.0), new DConstant(0.0))), 60), "dirty_trick"); PBECRegistry.register(new PBECPool(new DLinear(10.0, 30.0), Blocks.WATER, PandorasBoxHelper.blocks), "water_pool"); PBECRegistry.register(new PBECPool(new DLinear(10.0, 30.0), Blocks.LAVA, PandorasBoxHelper.blocks), "lava_pool"); -// ArrayList> blockArrayList = new ArrayList<>(); -// ArrayListExtensions stoneBricks = new ArrayListExtensions<>(); -// stoneBricks.addAll(new WeightedBlock(100, Blocks.STONE_BRICKS), new WeightedBlock(90, Blocks.CRACKED_STONE_BRICKS), new WeightedBlock(50, Blocks.MOSSY_STONE_BRICKS), new WeightedBlock(10, Blocks.CHISELED_STONE_BRICKS)); -// ArrayListExtensions blackstoneBricks = new ArrayListExtensions<>(); -// blackstoneBricks.addAll(new WeightedBlock(100, Blocks.POLISHED_BLACKSTONE_BRICKS), new WeightedBlock(90, Blocks.CRACKED_POLISHED_BLACKSTONE_BRICKS), new WeightedBlock(10, Blocks.CHISELED_POLISHED_BLACKSTONE)); -// blockArrayList.add(blackstoneBricks); -// blockArrayList.add(stoneBricks); -// ArrayListExtensions loot = new ArrayListExtensions<>(); -// loot.addAll(new RandomizedItemStack(Items.GOLD_NUGGET, 1, 5, 60), new RandomizedItemStack(Items.IRON_NUGGET, 1, 3, 35), new RandomizedItemStack(Items.FLINT, 1, 3, 80), new RandomizedItemStack(Items.FLINT_AND_STEEL, 1, 1, 20), new RandomizedItemStack(Items.OBSIDIAN, 1, 3, 10), new RandomizedItemStack(Items.ENCHANTED_GOLDEN_APPLE, 1, 3, 5), new RandomizedItemStack(Items.GOLDEN_AXE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_SWORD, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_HOE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_PICKAXE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_SHOVEL, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_HELMET, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_CHESTPLATE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_LEGGINGS, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_BOOTS, 1, 1, 20)); -// PBECRegistry.register(new PBECRuinedPortal(new ILinear(5, 15), new ILinear(5, 10), new ILinear(5, 15), new ILinear(2, 5), blockArrayList, loot, Direction.Axis.X), "gateway_to_hell_x"); -// PBECRegistry.register(new PBECRuinedPortal(new ILinear(5, 15), new ILinear(5, 10), new ILinear(5, 15), new ILinear(2, 5), blockArrayList, loot, Direction.Axis.Z), "gateway_to_hell_z"); +// WeightedBlock[][] blockArray = new WeightedBlock[][]{ +// new WeightedBlock[] { new WeightedBlock(100, Blocks.STONE_BRICKS), +// new WeightedBlock(90, Blocks.CRACKED_STONE_BRICKS), +// new WeightedBlock(10, Blocks.CHISELED_STONE_BRICKS), +// new WeightedBlock(90, Blocks.STONE_BRICK_SLAB), +// new WeightedBlock(90, Blocks.STONE_BRICK_STAIRS) }, +// new WeightedBlock[] { new WeightedBlock(100, Blocks.POLISHED_BLACKSTONE_BRICKS), +// new WeightedBlock(90, Blocks.CRACKED_POLISHED_BLACKSTONE_BRICKS), +// new WeightedBlock(10, Blocks.CHISELED_POLISHED_BLACKSTONE), +// new WeightedBlock(90, Blocks.POLISHED_BLACKSTONE_BRICK_SLAB), +// new WeightedBlock(90, Blocks.POLISHED_BLACKSTONE_BRICK_STAIRS) } +// }; +// ArrayListExtensions loot = new ArrayListExtensions<>(Arrays.asList(new RandomizedItemStack(Items.GOLD_NUGGET, 1, 5, 60), new RandomizedItemStack(Items.IRON_NUGGET, 1, 3, 35), new RandomizedItemStack(Items.FLINT, 1, 3, 80), new RandomizedItemStack(Items.FLINT_AND_STEEL, 1, 1, 20), new RandomizedItemStack(Items.OBSIDIAN, 1, 3, 10), new RandomizedItemStack(Items.ENCHANTED_GOLDEN_APPLE, 1, 3, 5), new RandomizedItemStack(Items.GOLDEN_AXE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_SWORD, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_HOE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_PICKAXE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_SHOVEL, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_HELMET, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_CHESTPLATE, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_LEGGINGS, 1, 1, 20), new RandomizedItemStack(Items.GOLDEN_BOOTS, 1, 1, 20))); +// PBECRegistry.register(new PBECMulti(new PBECRuinedPortal(new ILinear(5, 15), new ILinear(5, 10), new ILinear(2, 5), blockArray, loot), 80, new PBECConvertToNether(new DLinear(20.0, 40.0), new DGaussian(0.01, 0.15), "wastes"), 30, new PBECPool(new DLinear(5.0, 10.0), Blocks.LAVA, Collections.singletonList(new WeightedBlock(1, Blocks.AIR))), 0), "gateway_to_hell"); PBECRegistry.register(new PBECHeightNoise(new DLinear(8.0, 30.0), new ILinear(-16, 16), new ILinear(1, 32), new ILinear(1, 8)), "height_noise"); PBECRegistry.register(new PBECRandomShapes(new DLinear(40.0, 150.0), new DLinear(2.0, 5.0), new ILinear(3, 10), PandorasBoxHelper.blocks, new ZConstant(true)), "mad_geometry"); PBECRegistry.register(new PBECRandomShapes(new DLinear(40.0, 150.0), new DLinear(1.0, 3.0), new ILinear(10, 80), PandorasBoxHelper.blocks, new ZConstant(false)), "madder_geometry"); @@ -57,11 +60,11 @@ public static void registerEffectCreators() { PBECRegistry.register(new PBECSpawnLightning(new ILinear(40, 200), new ILinear(6, 40), new DLinear(10.0, 40.0)), "lightning"); PBECRegistry.register(new PBECConvertToDesert(new DLinear(10.0, 80.0)), "sand_for_dessert"); PBECRegistry.register(new PBECConvertToEnd(new DLinear(10.0, 80.0)), "in_the_end"); - PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), "wastes"), "hell_on_earth"); - PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), "soul_sand_valley"), "valley_of_souls"); - PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), "deltas"), "deltas_of_destruction"); - PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), "warped"), "forest_of_calm"); - PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), "crimson"), "forest_of_heat"); + PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), new DConstant(0), "wastes"), "hell_on_earth"); + PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), new DConstant(0), "soul_sand_valley"), "valley_of_souls"); + PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), new DConstant(0), "deltas"), "deltas_of_destruction"); + PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), new DConstant(0), "warped"), "forest_of_calm"); + PBECRegistry.register(new PBECConvertToNether(new DLinear(10.0, 80.0), new DConstant(0), "crimson"), "forest_of_heat"); PBECRegistry.register(new PBECConvertToLifeless(new DLinear(20.0, 80.0)), "lifeless"); PBECRegistry.register(new PBECSpawnEntities(new ILinear(20, 100), new ILinear(20, 200), new IConstant(1), new IConstant(0), new IConstant(0), new IConstant(0), Collections.singletonList(new WeightedEntity(100, "arrow", 1, 1)), new ValueThrow(new DLinear(0.05, 0.5), new DLinear(0.3, 0.8)), null), "trapped_tribe"); PBECRegistry.register(new PBECBuffEntities(new ILinear(60, 20 * 30), new IWeighted(1, 100, 2, 80, 3, 50), new DLinear(8.0, 25.0), 0.2f, PandorasBoxHelper.debuffs), "buffed_down"); diff --git a/src/main/java/ivorius/pandorasbox/init/Registry.java b/src/main/java/ivorius/pandorasbox/init/Registry.java index e92926a..6cd45d8 100644 --- a/src/main/java/ivorius/pandorasbox/init/Registry.java +++ b/src/main/java/ivorius/pandorasbox/init/Registry.java @@ -91,8 +91,7 @@ public static void init(IEventBus bus) { makePositiveOrNegative("dirty_trick", false); makePositiveOrNegative("water_pool", true); makePositiveOrNegative("lava_pool", false); -// makePositiveOrNegative("gateway_to_hell_x", false); -// makePositiveOrNegative("gateway_to_hell_z", false); +// makePositiveOrNegative("gateway_to_hell", false); makePositiveOrNegative("height_noise", false); makePositiveOrNegative("mad_geometry", false); makePositiveOrNegative("madder_geometry", false); diff --git a/src/main/java/ivorius/pandorasbox/math/IvMathHelper.java b/src/main/java/ivorius/pandorasbox/math/IvMathHelper.java index 755cc86..bb13c5a 100644 --- a/src/main/java/ivorius/pandorasbox/math/IvMathHelper.java +++ b/src/main/java/ivorius/pandorasbox/math/IvMathHelper.java @@ -125,11 +125,17 @@ public static boolean compareOffsets(double base, double origin, double offset) return base == origin + offset || base == origin - offset; } - public static boolean isBetween(int base, int origin, int offset) { + private static boolean isBetween(int base, int origin, int offset, boolean inclusive) { boolean bl = false; - for (int i = origin - offset; i < origin + offset; i++) { + for (int i = origin - offset + (inclusive ? 0 : 1); inclusive ? i <= origin + offset : i < origin + offset; i++) { bl |= base == i; } return bl; } + public static boolean isBetween(int base, int origin, int offset) { + return isBetween(base, origin, offset, false); + } + public static boolean isBetweenInclusive(int base, int origin, int offset) { + return isBetween(base, origin, offset, true); + } } diff --git a/src/main/java/ivorius/pandorasbox/utils/PBNBTHelper.java b/src/main/java/ivorius/pandorasbox/utils/PBNBTHelper.java index eb4f9a5..ec11390 100644 --- a/src/main/java/ivorius/pandorasbox/utils/PBNBTHelper.java +++ b/src/main/java/ivorius/pandorasbox/utils/PBNBTHelper.java @@ -7,7 +7,6 @@ import net.minecraft.entity.EntityType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.DoubleNBT; import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.StringNBT; import net.minecraft.potion.EffectInstance; @@ -279,9 +278,10 @@ public static WeightedBlock[] readNBTWeightedBlocks(String id, CompoundNBT compo ListNBT listNBT = compound.getList(id, 8); WeightedBlock[] blocks = new WeightedBlock[listNBT.size()]; - for (int i = 0; i < blocks.length; i += 2) { - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(listNBT.getString(i))); - double weight = listNBT.getDouble(i + 1); + for (int i = 0; i < blocks.length; i++) { + CompoundNBT compoundNBT = listNBT.getCompound(i); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(compoundNBT.getString("block"))); + double weight = compoundNBT.getDouble("weight"); blocks[i] = new WeightedBlock(weight, block); } @@ -296,8 +296,10 @@ public static void writeNBTWeightedBlocks(String id, WeightedBlock[] blocks, Com ListNBT listNBT = new ListNBT(); for (WeightedBlock b : blocks) { - listNBT.add(StringNBT.valueOf(PBNBTHelper.storeBlockString(b.block))); - listNBT.add(DoubleNBT.valueOf(b.weight)); + CompoundNBT compoundNBT = new CompoundNBT(); + compoundNBT.putString("block", PBNBTHelper.storeBlockString(b.block)); + compoundNBT.putDouble("weight", b.weight); + listNBT.add(compoundNBT); } compound.put(id, listNBT); @@ -337,7 +339,7 @@ public static RandomizedItemStack[] readNBTRandomizedStacks(String id, CompoundN if (compoundNBT.contains("max")) max = compoundNBT.getInt("max"); if (compoundNBT.contains("weight")) - max = compoundNBT.getInt("weight"); + weight = compoundNBT.getInt("weight"); itemStacks[i] = new RandomizedItemStack(stack, min, max, weight); } diff --git a/src/main/java/ivorius/pandorasbox/weighted/WeightedBlock.java b/src/main/java/ivorius/pandorasbox/weighted/WeightedBlock.java index cc7ebce..14da79a 100644 --- a/src/main/java/ivorius/pandorasbox/weighted/WeightedBlock.java +++ b/src/main/java/ivorius/pandorasbox/weighted/WeightedBlock.java @@ -10,14 +10,12 @@ /** * Created by lukas on 31.03.14. */ -public class WeightedBlock implements WeightedSelector.Item -{ +public class WeightedBlock implements WeightedSelector.Item { public double weight; public Block block; - public WeightedBlock(double weight, Block block) - { + public WeightedBlock(double weight, Block block) { this.weight = weight; this.block = block; } diff --git a/src/main/java/ivorius/pandorasbox/weighted/WeightedSelector.java b/src/main/java/ivorius/pandorasbox/weighted/WeightedSelector.java index 2fd43df..e81fe9c 100644 --- a/src/main/java/ivorius/pandorasbox/weighted/WeightedSelector.java +++ b/src/main/java/ivorius/pandorasbox/weighted/WeightedSelector.java @@ -10,28 +10,23 @@ @SuppressWarnings("unused") public class WeightedSelector { - public static double totalWeight(Collection items) - { + public static double totalWeight(Collection items) { return items.stream().mapToDouble(Item::weight).reduce(0, Double::sum); } - public static double totalWeight(Collection items, final ToDoubleFunction weightFunction) - { + public static double totalWeight(Collection items, final ToDoubleFunction weightFunction) { return items.stream().mapToDouble(weightFunction).reduce(0, Double::sum); } - public static boolean canSelect(Collection items) - { + public static boolean canSelect(Collection items) { return items.stream().anyMatch(item -> item.weight() > 0); } - public static boolean canSelect(Collection items, ToDoubleFunction weightFunction) - { + public static boolean canSelect(Collection items, ToDoubleFunction weightFunction) { return items.stream().anyMatch(item -> weightFunction.applyAsDouble(item) > 0); } - public static T selectWeightless(Random rand, Collection items, int counted) - { + public static T selectWeightless(Random rand, Collection items, int counted) { counted = rand.nextInt(counted); for (Iterator iterator = items.iterator(); true; ) { @@ -41,24 +36,20 @@ public static T selectWeightless(Random rand, Collection items, int count } } - public static T selectItem(Random rand, Collection items) - { + public static T selectItem(Random rand, Collection items) { return selectItem(rand, items, totalWeight(items)); } - public static T selectItem(Random rand, Collection items, double totalWeight) - { + public static T selectItem(Random rand, Collection items, double totalWeight) { return selectItem(rand, items, totalWeight, false); } - public static T selectItem(Random rand, Collection items, boolean remove) - { + public static T selectItem(Random rand, Collection items, boolean remove) { return selectItem(rand, items, totalWeight(items), remove); } - public static T selectItem(Random rand, Collection items, double totalWeight, boolean remove) - { - if (items.size() == 0) + public static T selectItem(Random rand, Collection items, double totalWeight, boolean remove) { + if (items.isEmpty()) throw new IndexOutOfBoundsException(); double random = rand.nextDouble() * totalWeight; @@ -78,24 +69,20 @@ public static T selectItem(Random rand, Collection items, do return selectWeightless(rand, items, counted); } - public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction) - { + public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction) { return select(rand, items, weightFunction, totalWeight(items, weightFunction)); } - public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, double totalWeight) - { + public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, double totalWeight) { return select(rand, items, weightFunction, totalWeight, false); } - public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, boolean remove) - { + public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, boolean remove) { return select(rand, items, weightFunction, totalWeight(items, weightFunction), remove); } - public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, double totalWeight, boolean remove) - { - if (items.size() == 0) + public static T select(Random rand, Collection items, final ToDoubleFunction weightFunction, double totalWeight, boolean remove) { + if (items.isEmpty()) throw new IndexOutOfBoundsException(); double random = rand.nextDouble() * totalWeight; @@ -115,76 +102,62 @@ public static T select(Random rand, Collection items, final ToDoubleFunct return selectWeightless(rand, items, counted); } - public static T select(Random rand, Collection> items) - { + public static T select(Random rand, Collection> items) { return selectItem(rand, items).getItem(); } - public static T select(Random rand, Collection> items, double totalWeight) - { + public static T select(Random rand, Collection> items, double totalWeight) { return selectItem(rand, items, totalWeight).getItem(); } - public static T select(Random rand, Collection> items, boolean remove) - { + public static T select(Random rand, Collection> items, boolean remove) { return selectItem(rand, items, remove).getItem(); } - public static T select(Random rand, Collection> items, double totalWeight, boolean remove) - { + public static T select(Random rand, Collection> items, double totalWeight, boolean remove) { return selectItem(rand, items, totalWeight, remove).getItem(); } - public interface Item - { + public interface Item { double weight(); } - public static class SimpleItem implements Item, Comparable - { + public static class SimpleItem implements Item, Comparable { protected final double weight; protected final T item; - public SimpleItem(double weight, T item) - { + public SimpleItem(double weight, T item) { this.item = item; this.weight = weight; } - public static SimpleItem of(double weight, T item) - { + public static SimpleItem of(double weight, T item) { return new SimpleItem<>(weight, item); } - public static List> apply(Stream items, final ToDoubleFunction weightFunction) - { + public static List> apply(Stream items, final ToDoubleFunction weightFunction) { return items.map(input -> new SimpleItem<>(weightFunction.applyAsDouble(input), input)).collect(Collectors.toList()); } - public static Collection> apply(Collection items, final ToDoubleFunction weightFunction) - { + public static Collection> apply(Collection items, final ToDoubleFunction weightFunction) { return Collections2.transform(items, item -> new SimpleItem<>(weightFunction.applyAsDouble(item), item)); } - public static List> apply(List items, final ToDoubleFunction weightFunction) - { + public static List> apply(List items, final ToDoubleFunction weightFunction) { return apply(items.stream(), weightFunction); } - public T getItem() - { + public T getItem() { return item; } @Override - public double weight() - { + public double weight() { return weight; } @Override - public boolean equals(Object o) - { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; @@ -195,8 +168,7 @@ public boolean equals(Object o) } @Override - public int hashCode() - { + public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(weight); @@ -206,8 +178,7 @@ public int hashCode() } @Override - public String toString() - { + public String toString() { return "SimpleItem{" + "weight=" + weight + ", item=" + item + @@ -215,17 +186,14 @@ public String toString() } @Override - public int compareTo(Item o) - { + public int compareTo(Item o) { return Double.compare(weight, o.weight()); } } - public static class ItemComparator implements Comparator - { + public static class ItemComparator implements Comparator { @Override - public int compare(Item o1, Item o2) - { + public int compare(Item o1, Item o2) { return Double.compare(o1.weight(), o2.weight()); } }