Added new meteor types (#4428)

This commit is contained in:
yueh
2020-06-22 22:18:21 +02:00
committed by GitHub
parent f32289d881
commit adf1bd0191
25 changed files with 563 additions and 470 deletions
@@ -18,30 +18,65 @@
package appeng.debug;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.play.server.SChunkDataPacket;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.server.ServerWorld;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import appeng.worldgen.MeteoritePlacer;
import appeng.worldgen.MeteoriteSpawner;
import appeng.worldgen.PlacedMeteoriteSettings;
import appeng.worldgen.meteorite.CraterType;
import appeng.worldgen.meteorite.MeteoritePlacer;
import appeng.worldgen.meteorite.MeteoriteSpawner;
import appeng.worldgen.meteorite.PlacedMeteoriteSettings;
public class MeteoritePlacerItem extends AEBaseItem {
private static final String MODE_TAG = "mode";
public MeteoritePlacerItem(Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
if (world.isRemote()) {
return ActionResult.resultPass(player.getHeldItem(hand));
}
if (player.isSneaking()) {
final ItemStack itemStack = player.getHeldItem(hand);
final CompoundNBT tag = itemStack.getOrCreateTag();
if (tag.contains(MODE_TAG)) {
final byte mode = tag.getByte("mode");
tag.putByte(MODE_TAG, (byte) ((mode + 1) % CraterType.values().length));
} else {
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
}
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
player.sendMessage(new StringTextComponent(craterType.name()));
return ActionResult.resultSuccess(itemStack);
}
return super.onItemRightClick(world, player, hand);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
@@ -56,23 +91,28 @@ public class MeteoritePlacerItem extends AEBaseItem {
return ActionResultType.PASS;
}
CompoundNBT tag = stack.getOrCreateTag();
if (!tag.contains(MODE_TAG)) {
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
}
// See MeteoriteStructure for original code
float coreRadius = (Platform.getRandomFloat() * 6.0f) + 2;
boolean lava = Platform.getRandomFloat() > 0.9f;
boolean pureCrater = Platform.getRandomFloat() > 0.5f;
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
MeteoriteSpawner spawner = new MeteoriteSpawner();
PlacedMeteoriteSettings spawned = spawner.trySpawnMeteoriteAtSuitableHeight(world, pos, coreRadius, lava);
PlacedMeteoriteSettings spawned = spawner.trySpawnMeteoriteAtSuitableHeight(world, pos, coreRadius, craterType,
pureCrater, false);
if (spawned == null) {
player.sendMessage(new StringTextComponent("Un-suitable Location."));
return ActionResultType.FAIL;
}
player.sendMessage(new StringTextComponent("Spawned at y=" + spawned.getPos().getY()));
// Since we don't know yet if the meteorite will be underground or not,
// we have to assume maximum size
int range = (int) Math.ceil((coreRadius * 2 + 5) * 1.25f);
int range = (int) Math.ceil((coreRadius * 2 + 5) * 5f);
MutableBoundingBox boundingBox = new MutableBoundingBox(pos.getX() - range, pos.getY(), pos.getZ() - range,
pos.getX() + range, pos.getY(), pos.getZ() + range);
@@ -80,6 +120,9 @@ public class MeteoritePlacerItem extends AEBaseItem {
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned, boundingBox);
placer.place();
player.sendMessage(new StringTextComponent("Spawned at y=" + spawned.getPos().getY() + " range=" + range
+ " biomeCategory=" + world.getBiome(pos).getCategory()));
// The placer will not send chunks to the player since it's used as part
// of world-gen normally, so we'll have to do it ourselves. Since this
// is a debug tool, we'll not care about being terribly efficient here