update to 24w33a
This commit is contained in:
1 parent
9940feb7d3
commit
d11586fdaf
58 files changed
+379
-875
No files matched your search
@@ -100,7 +100,7 @@ public class BlockRotator
|
||||
}
|
||||
}
|
||||
// Send block update to the block that just have been rotated.
|
||||
world.neighborChanged(blockpos, block, source.pos());
|
||||
world.neighborChanged(blockpos, block, null);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import carpet.script.utils.Tracer;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetHeldSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -282,7 +282,7 @@ public class EntityPlayerActionPack
|
||||
public void setSlot(int slot)
|
||||
{
|
||||
player.getInventory().selected = slot-1;
|
||||
player.connection.send(new ClientboundSetCarriedItemPacket(slot-1));
|
||||
player.connection.send(new ClientboundSetHeldSlotPacket(slot-1));
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
@@ -317,9 +317,9 @@ public class EntityPlayerActionPack
|
||||
if (pos.getY() < player.level().getMaxBuildHeight() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos))
|
||||
{
|
||||
InteractionResult result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
|
||||
if (result.consumesAction())
|
||||
if (result instanceof InteractionResult.Success success)
|
||||
{
|
||||
if (result.shouldSwing()) player.swing(hand);
|
||||
if (success.swingSource() == InteractionResult.SwingSource.SERVER) player.swing(hand);
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.fakes.IngredientInterface;
|
||||
import carpet.fakes.RecipeManagerInterface;
|
||||
import carpet.utils.Messenger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap;
|
||||
@@ -22,7 +21,7 @@ import net.minecraft.world.item.DyeItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.PlacementInfo;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.AbstractBannerBlock;
|
||||
@@ -32,12 +31,12 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
@@ -376,16 +375,13 @@ public class HopperCounter
|
||||
{
|
||||
for (Recipe<?> r: ((RecipeManagerInterface) CarpetServer.minecraft_server.getRecipeManager()).getAllMatching(type, id, registryAccess))
|
||||
{
|
||||
for (Ingredient ingredient: r.getIngredients())
|
||||
for (Optional<PlacementInfo.SlotInfo> ingredient: r.placementInfo().slotInfo())
|
||||
{
|
||||
for (Collection<ItemStack> stacks : ((IngredientInterface) (Object) ingredient).getRecipeStacks())
|
||||
for(ItemStack stack : ingredient.get().possibleItems())
|
||||
{
|
||||
for (ItemStack iStak : stacks)
|
||||
{
|
||||
TextColor cand = fromItem(iStak.getItem(), registryAccess);
|
||||
if (cand != null)
|
||||
return cand;
|
||||
}
|
||||
TextColor cand = fromItem(stack.getItem(), registryAccess);
|
||||
if (cand != null)
|
||||
return cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,39 @@
|
||||
package carpet.helpers;
|
||||
//Author: masa
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.item.PrimedTnt;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import carpet.logging.logHelpers.ExplosionLogHelper;
|
||||
import carpet.mixins.ExplosionAccessor;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.utils.Messenger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.EXPLOSION_OUTCOME;
|
||||
|
||||
public class OptimizedExplosion
|
||||
{
|
||||
private static List<Entity> entitylist;
|
||||
private static Vec3 vec3dmem;
|
||||
private static long tickmem;
|
||||
// For disabling the explosion particles and sound
|
||||
public static int explosionSound = 0;
|
||||
|
||||
// masa's optimizations
|
||||
private static Object2DoubleOpenHashMap<Pair<Vec3, AABB>> densityCache = new Object2DoubleOpenHashMap<>();
|
||||
private static MutablePair<Vec3, AABB> pairMutable = new MutablePair<>();
|
||||
private static Object2ObjectOpenHashMap<BlockPos, BlockState> stateCache = new Object2ObjectOpenHashMap<>();
|
||||
private static Object2ObjectOpenHashMap<BlockPos, FluidState> fluidCache = new Object2ObjectOpenHashMap<>();
|
||||
private static BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos(0, 0, 0);
|
||||
private static ObjectOpenHashSet<BlockPos> affectedBlockPositionsSet = new ObjectOpenHashSet<>();
|
||||
private static boolean firstRay;
|
||||
private static boolean rayCalcDone;
|
||||
private static ArrayList<Float> chances = new ArrayList<>();
|
||||
private static BlockPos blastChanceLocation;
|
||||
|
||||
// Creating entity list for scarpet event
|
||||
private static List<Entity> entityList = new ArrayList<>();
|
||||
|
||||
public static void doExplosionA(Explosion e, ExplosionLogHelper eLogger) {
|
||||
public static List<BlockPos> doExplosionA(Explosion e, ExplosionLogHelper eLogger) {
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
|
||||
entityList.clear();
|
||||
boolean eventNeeded = EXPLOSION_OUTCOME.isNeeded() && !eAccess.getLevel().isClientSide();
|
||||
blastCalc(e);
|
||||
|
||||
List<BlockPos> toBlow;
|
||||
|
||||
if (!CarpetSettings.explosionNoBlockDamage && eAccess.getDamageSource() != null) {
|
||||
rayCalcDone = false;
|
||||
@@ -88,291 +47,14 @@ public class OptimizedExplosion
|
||||
stateCache.clear();
|
||||
fluidCache.clear();
|
||||
|
||||
e.getToBlow().addAll(affectedBlockPositionsSet);
|
||||
toBlow = new ArrayList<>(affectedBlockPositionsSet);
|
||||
affectedBlockPositionsSet.clear();
|
||||
} else {
|
||||
toBlow = Collections.emptyList();
|
||||
}
|
||||
|
||||
float f3 = eAccess.getRadius() * 2.0F;
|
||||
int k1 = Mth.floor(eAccess.getX() - (double) f3 - 1.0D);
|
||||
int l1 = Mth.floor(eAccess.getX() + (double) f3 + 1.0D);
|
||||
int i2 = Mth.floor(eAccess.getY() - (double) f3 - 1.0D);
|
||||
int i1 = Mth.floor(eAccess.getY() + (double) f3 + 1.0D);
|
||||
int j2 = Mth.floor(eAccess.getZ() - (double) f3 - 1.0D);
|
||||
int j1 = Mth.floor(eAccess.getZ() + (double) f3 + 1.0D);
|
||||
Vec3 vec3d = new Vec3(eAccess.getX(), eAccess.getY(), eAccess.getZ());
|
||||
|
||||
if (vec3dmem == null || !vec3dmem.equals(vec3d) || tickmem != eAccess.getLevel().getGameTime()) {
|
||||
vec3dmem = vec3d;
|
||||
tickmem = eAccess.getLevel().getGameTime();
|
||||
entitylist = eAccess.getLevel().getEntities(null, new AABB(k1, i2, j2, l1, i1, j1));
|
||||
explosionSound = 0;
|
||||
}
|
||||
|
||||
explosionSound++;
|
||||
|
||||
Entity explodingEntity = eAccess.getSource();
|
||||
for (int k2 = 0; k2 < entitylist.size(); ++k2) {
|
||||
Entity entity = entitylist.get(k2);
|
||||
|
||||
|
||||
if (entity == explodingEntity) {
|
||||
// entitylist.remove(k2);
|
||||
removeFast(entitylist, k2);
|
||||
k2--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity instanceof PrimedTnt && explodingEntity != null &&
|
||||
entity.getX() == explodingEntity.getX() &&
|
||||
entity.getY() == explodingEntity.getY() &&
|
||||
entity.getZ() == explodingEntity.getZ()) {
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3(0,-0.9923437498509884d, 0));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entity.ignoreExplosion(e)) {
|
||||
double d12 = Math.sqrt(entity.distanceToSqr(eAccess.getX(), eAccess.getY(), eAccess.getZ())) / (double) f3;
|
||||
|
||||
if (d12 <= 1.0D) {
|
||||
double d5 = entity.getX() - eAccess.getX();
|
||||
// Change in 1.16 snapshots to fix a bug with TNT jumping
|
||||
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - eAccess.getY();
|
||||
double d9 = entity.getZ() - eAccess.getZ();
|
||||
double d13 = (double) Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
|
||||
|
||||
if (d13 != 0.0D) {
|
||||
d5 = d5 / d13;
|
||||
d7 = d7 / d13;
|
||||
d9 = d9 / d13;
|
||||
double density;
|
||||
|
||||
pairMutable.setLeft(vec3d);
|
||||
pairMutable.setRight(entity.getBoundingBox());
|
||||
density = densityCache.getOrDefault(pairMutable, Double.MAX_VALUE);
|
||||
|
||||
if (density == Double.MAX_VALUE)
|
||||
{
|
||||
Pair<Vec3, AABB> pair = Pair.of(vec3d, entity.getBoundingBox());
|
||||
density = Explosion.getSeenPercent(vec3d, entity);
|
||||
densityCache.put(pair, density);
|
||||
}
|
||||
|
||||
// If it is needed, it saves the entity
|
||||
if (eventNeeded) {
|
||||
entityList.add(entity);
|
||||
}
|
||||
|
||||
double d10 = (1.0D - d12) * density;
|
||||
if (eAccess.getDamageSource() != null)
|
||||
{
|
||||
entity.hurt(eAccess.getDamageSource(),
|
||||
(float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
|
||||
}
|
||||
double d11 = d10;
|
||||
|
||||
if (entity instanceof LivingEntity lev) {
|
||||
d11 = d10 * Mth.clamp(1.0 - lev.getAttributeValue(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE), 0.0, 1.0);
|
||||
}
|
||||
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3(d5 * d11, d7 * d11, d9 * d11));
|
||||
}
|
||||
|
||||
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
|
||||
if (!player.isSpectator()
|
||||
&& (!player.isCreative() || !player.getAbilities().flying)) { //getAbilities
|
||||
e.getHitPlayers().put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
densityCache.clear();
|
||||
}
|
||||
|
||||
public static void doExplosionB(Explosion e, boolean spawnParticles)
|
||||
{
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
Level world = eAccess.getLevel();
|
||||
double posX = eAccess.getX();
|
||||
double posY = eAccess.getY();
|
||||
double posZ = eAccess.getZ();
|
||||
|
||||
// If it is needed, calls scarpet event
|
||||
if (EXPLOSION_OUTCOME.isNeeded() && !world.isClientSide()) {
|
||||
EXPLOSION_OUTCOME.onExplosion((ServerLevel) world, eAccess.getSource(), e::getIndirectSourceEntity, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getRadius(), eAccess.isFire(), e.getToBlow(), entityList, eAccess.getBlockInteraction());
|
||||
}
|
||||
|
||||
boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.KEEP;
|
||||
|
||||
// explosionSound incremented till disabling the explosion particles and sound
|
||||
if (explosionSound < 100 || explosionSound % 100 == 0)
|
||||
{
|
||||
world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE.value(), SoundSource.BLOCKS, 4.0F,
|
||||
(1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F);
|
||||
|
||||
if (spawnParticles)
|
||||
{
|
||||
if (eAccess.getRadius() >= 2.0F && damagesTerrain)
|
||||
{
|
||||
world.addParticle(ParticleTypes.EXPLOSION_EMITTER, posX, posY, posZ, 1.0D, 0.0D, 0.0D);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.addParticle(ParticleTypes.EXPLOSION, posX, posY, posZ, 1.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (damagesTerrain)
|
||||
{
|
||||
ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList = new ObjectArrayList<>();
|
||||
Util.shuffle((ObjectArrayList<BlockPos>) e.getToBlow(), world.random);
|
||||
|
||||
boolean dropFromExplosions = CarpetSettings.xpFromExplosions || e.getIndirectSourceEntity() instanceof Player;
|
||||
|
||||
for (BlockPos blockpos : e.getToBlow())
|
||||
{
|
||||
BlockState state = world.getBlockState(blockpos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (!state.isAir())
|
||||
{
|
||||
if (block.dropFromExplosion(e) && world instanceof ServerLevel serverLevel)
|
||||
{
|
||||
BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(blockpos) : null; //hasBlockEntity()
|
||||
|
||||
LootParams.Builder lootBuilder = (new LootParams.Builder((ServerLevel)eAccess.getLevel()))
|
||||
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos))
|
||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
|
||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity)
|
||||
.withOptionalParameter(LootContextParams.THIS_ENTITY, eAccess.getSource());
|
||||
|
||||
if (eAccess.getBlockInteraction() == Explosion.BlockInteraction.DESTROY_WITH_DECAY)
|
||||
lootBuilder.withParameter(LootContextParams.EXPLOSION_RADIUS, eAccess.getRadius());
|
||||
|
||||
state.spawnAfterBreak(serverLevel, blockpos, ItemStack.EMPTY, dropFromExplosions);
|
||||
|
||||
state.getDrops(lootBuilder).forEach((itemStackx) -> {
|
||||
method_24023(objectArrayList, itemStackx, blockpos.immutable());
|
||||
});
|
||||
}
|
||||
|
||||
world.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
|
||||
block.wasExploded(world, blockpos, e);
|
||||
}
|
||||
}
|
||||
objectArrayList.forEach(p -> Block.popResource(world, p.getRight(), p.getLeft()));
|
||||
|
||||
}
|
||||
|
||||
if (eAccess.isFire())
|
||||
{
|
||||
for (BlockPos blockpos1 : e.getToBlow())
|
||||
{
|
||||
// Use the same Chunk reference because the positions are in the same xz-column
|
||||
ChunkAccess chunk = world.getChunk(blockpos1.getX() >> 4, blockpos1.getZ() >> 4);
|
||||
|
||||
BlockPos down = blockpos1.below(1);
|
||||
if (eAccess.getRandom().nextInt(3) == 0 &&
|
||||
chunk.getBlockState(blockpos1).isAir() &&
|
||||
chunk.getBlockState(down).isSolidRender(world, down)
|
||||
)
|
||||
{
|
||||
world.setBlockAndUpdate(blockpos1, Blocks.FIRE.defaultBlockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copied from Explosion, need to move the code to the explosion code anyways and use shadows for
|
||||
// simplicity, its not jarmodding anyways
|
||||
private static void method_24023(ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList, ItemStack itemStack, BlockPos blockPos) {
|
||||
int i = objectArrayList.size();
|
||||
|
||||
for(int j = 0; j < i; ++j) {
|
||||
Pair<ItemStack, BlockPos> pair = objectArrayList.get(j);
|
||||
ItemStack itemStack2 = pair.getLeft();
|
||||
if (ItemEntity.areMergable(itemStack2, itemStack)) {
|
||||
ItemStack itemStack3 = ItemEntity.merge(itemStack2, itemStack, 16);
|
||||
objectArrayList.set(j, Pair.of(itemStack3, pair.getRight()));
|
||||
if (itemStack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
objectArrayList.add(Pair.of(itemStack, blockPos));
|
||||
}
|
||||
|
||||
private static void removeFast(List<Entity> lst, int index) {
|
||||
if (index < lst.size() - 1)
|
||||
lst.set(index, lst.get(lst.size() - 1));
|
||||
lst.remove(lst.size() - 1);
|
||||
}
|
||||
|
||||
private static void rayCalcs(Explosion e) {
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
boolean first = true;
|
||||
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
for (int k = 0; k < 16; ++k) {
|
||||
for (int l = 0; l < 16; ++l) {
|
||||
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
|
||||
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
|
||||
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
|
||||
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
|
||||
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
||||
d0 = d0 / d3;
|
||||
d1 = d1 / d3;
|
||||
d2 = d2 / d3;
|
||||
float rand = eAccess.getLevel().random.nextFloat();
|
||||
if (CarpetSettings.tntRandomRange >= 0) {
|
||||
rand = (float) CarpetSettings.tntRandomRange;
|
||||
}
|
||||
float f = eAccess.getRadius() * (0.7F + rand * 0.6F);
|
||||
double d4 = eAccess.getX();
|
||||
double d6 = eAccess.getY();
|
||||
double d8 = eAccess.getZ();
|
||||
|
||||
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
|
||||
BlockPos blockpos = BlockPos.containing(d4, d6, d8);
|
||||
BlockState state = eAccess.getLevel().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getLevel().getFluidState(blockpos);
|
||||
|
||||
if (!state.isAir()) {
|
||||
float f2 = Math.max(state.getBlock().getExplosionResistance(), fluidState.getExplosionResistance());
|
||||
if (eAccess.getSource() != null)
|
||||
f2 = eAccess.getSource().getBlockExplosionResistance(e, eAccess.getLevel(), blockpos, state, fluidState, f2);
|
||||
f -= (f2 + 0.3F) * 0.3F;
|
||||
}
|
||||
|
||||
if (f > 0.0F && (eAccess.getSource() == null ||
|
||||
eAccess.getSource().shouldBlockExplode(e, eAccess.getLevel(), blockpos, state, f)))
|
||||
{
|
||||
affectedBlockPositionsSet.add(blockpos);
|
||||
}
|
||||
else if (first) {
|
||||
return;
|
||||
}
|
||||
|
||||
first = false;
|
||||
|
||||
d4 += d0 * 0.30000001192092896D;
|
||||
d6 += d1 * 0.30000001192092896D;
|
||||
d8 += d2 * 0.30000001192092896D;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return toBlow;
|
||||
}
|
||||
|
||||
private static void getAffectedPositionsOnPlaneX(Explosion e, int x, int yStart, int yEnd, int zStart, int zEnd)
|
||||
@@ -454,9 +136,10 @@ public class OptimizedExplosion
|
||||
float rand = eAccess.getLevel().random.nextFloat();
|
||||
float sizeRand = (CarpetSettings.tntRandomRange >= 0 ? (float) CarpetSettings.tntRandomRange : rand);
|
||||
float size = eAccess.getRadius() * (0.7F + sizeRand * 0.6F);
|
||||
double posX = eAccess.getX();
|
||||
double posY = eAccess.getY();
|
||||
double posZ = eAccess.getZ();
|
||||
Vec3 vec3 = eAccess.getCenter();
|
||||
double posX = vec3.x;
|
||||
double posY = vec3.y;
|
||||
double posZ = vec3.z;
|
||||
|
||||
for (float f1 = 0.3F; size > 0.0F; size -= 0.22500001F)
|
||||
{
|
||||
@@ -508,112 +191,4 @@ public class OptimizedExplosion
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setBlastChanceLocation(BlockPos p){
|
||||
blastChanceLocation = p;
|
||||
}
|
||||
|
||||
private static void blastCalc(Explosion e){
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
if(blastChanceLocation == null || blastChanceLocation.distToLowCornerSqr(eAccess.getX(), eAccess.getY(), eAccess.getZ()) > 200) return;
|
||||
chances.clear();
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
for (int k = 0; k < 16; ++k) {
|
||||
for (int l = 0; l < 16; ++l) {
|
||||
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
|
||||
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
|
||||
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
|
||||
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
|
||||
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
||||
d0 = d0 / d3;
|
||||
d1 = d1 / d3;
|
||||
d2 = d2 / d3;
|
||||
float f = eAccess.getRadius() * (0.7F + 0.6F);
|
||||
double d4 = eAccess.getX();
|
||||
double d6 = eAccess.getY();
|
||||
double d8 = eAccess.getZ();
|
||||
boolean found = false;
|
||||
|
||||
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
|
||||
BlockPos blockpos = BlockPos.containing(d4, d6, d8);
|
||||
BlockState state = eAccess.getLevel().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getLevel().getFluidState(blockpos);
|
||||
|
||||
if (!state.isAir()) {
|
||||
float f2 = Math.max(state.getBlock().getExplosionResistance(), fluidState.getExplosionResistance());
|
||||
if (eAccess.getSource() != null)
|
||||
f2 = eAccess.getSource().getBlockExplosionResistance(e, eAccess.getLevel(), blockpos, state, fluidState, f2);
|
||||
f -= (f2 + 0.3F) * 0.3F;
|
||||
}
|
||||
|
||||
if (f > 0.0F && (eAccess.getSource() == null ||
|
||||
eAccess.getSource().shouldBlockExplode(e, eAccess.getLevel(), blockpos, state, f))) {
|
||||
if(!found && blockpos.equals(blastChanceLocation)){
|
||||
chances.add(f);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
d4 += d0 * 0.30000001192092896D;
|
||||
d6 += d1 * 0.30000001192092896D;
|
||||
d8 += d2 * 0.30000001192092896D;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//showTNTblastChance(e);
|
||||
}
|
||||
|
||||
private static void showTNTblastChance(Explosion e){
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
double randMax = 0.6F * eAccess.getRadius();
|
||||
double total = 0;
|
||||
boolean fullyBlownUp = false;
|
||||
boolean first = true;
|
||||
int rays = 0;
|
||||
for(float f3 : chances){
|
||||
rays++;
|
||||
double calc = f3 - randMax;
|
||||
if(calc > 0) fullyBlownUp = true;
|
||||
double chancePerRay = (Math.abs(calc) / randMax);
|
||||
if(!fullyBlownUp){
|
||||
if(first){
|
||||
first = false;
|
||||
total = chancePerRay;
|
||||
}else {
|
||||
total = total * chancePerRay;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fullyBlownUp) total = 0;
|
||||
double chance = 1 - total;
|
||||
NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
nf.setRoundingMode (RoundingMode.DOWN);
|
||||
nf.setMaximumFractionDigits(2);
|
||||
for(Player player : eAccess.getLevel().players()){
|
||||
Messenger.m(player,"w Pop: ",
|
||||
"c " + nf.format(chance) + " ",
|
||||
"^w Chance for the block to be destroyed by the blast: " + chance,
|
||||
"?" + chance,
|
||||
"w Remain: ",
|
||||
String.format("c %.2f ", total),
|
||||
"^w Chance the block survives the blast: " + total,
|
||||
"?" + total,
|
||||
"w Rays: ",
|
||||
String.format("c %d ", rays),
|
||||
"^w TNT blast rays going through the block",
|
||||
"?" + rays,
|
||||
"w Size: ",
|
||||
String.format("c %.1f ", eAccess.getRadius()),
|
||||
"^w TNT blast size",
|
||||
"?" + eAccess.getRadius(),
|
||||
"w @: ",
|
||||
String.format("c [%.1f %.1f %.1f] ", eAccess.getX(), eAccess.getY(), eAccess.getZ()),
|
||||
"^w TNT blast location X:" + eAccess.getX() + " Y:" + eAccess.getY() + " Z:" + eAccess.getZ(),
|
||||
"?" + eAccess.getX() + " " + eAccess.getY() + " " + eAccess.getZ()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,7 +676,7 @@ public class RedstoneWireTurbo
|
||||
// call BlockStateBase#neighborChanged directly. This change mostly
|
||||
// restores old behavior, at the cost of bypassing the
|
||||
// max-chained-neighbor-updates server property.
|
||||
worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, upd.parent, false);
|
||||
worldIn.getBlockState(upd.self).handleNeighborChanged(worldIn, upd.self, wire, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user