Merge branch 'master' into 1.15

# Conflicts:
#	src/main/java/carpet/mixins/TntEntityMixin.java
#	src/main/java/carpet/script/value/EntityValue.java
This commit is contained in:
gnembon committed 2019-10-23 08:58:57 -03:00
commit f41ae0f00e
16 files changed
+848 -13

No files matched your search

@@ -0,0 +1,55 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.script.ExpressionInspector;
import carpet.settings.CarpetSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.world.World;
import org.apache.commons.lang3.StringUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Optional;
@Mixin(ArmorStandEntity.class)
public abstract class ArmorStandEntity_scarpetMarkerMixin extends LivingEntity
{
protected ArmorStandEntity_scarpetMarkerMixin(EntityType<? extends LivingEntity> entityType_1, World world_1)
{
super(entityType_1, world_1);
}
/**
* Remove all markers that do not belong to any script host and not part of the global one when loaded
* @param ci
*/
@Inject(method = "readCustomDataFromTag", at = @At("HEAD"))
private void checkScarpetMarkerUnloaded(CallbackInfo ci)
{
if ((CarpetSettings.scriptsAutoload || CarpetSettings.commandScript) && !world.isClient)
{
if (getScoreboardTags().contains(ExpressionInspector.MARKER_STRING))
{
String prefix = ExpressionInspector.MARKER_STRING+"_";
Optional<String> owner = getScoreboardTags().stream().filter(s -> s.startsWith(prefix)).findFirst();
if (owner.isPresent())
{
String hostName = StringUtils.removeStart(owner.get(),prefix);
if (!hostName.isEmpty() && CarpetServer.scriptServer.getHostByName(hostName) == null)
{
remove();
}
}
else
{
remove();
}
}
}
}
}
@@ -0,0 +1,41 @@
package carpet.mixins;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Random;
@Mixin(Explosion.class)
public interface ExplosionAccessor {
@Accessor
boolean isCreateFire();
@Accessor
Explosion.DestructionType getBlockDestructionType();
@Accessor
World getWorld();
@Accessor
Random getRandom();
@Accessor
double getX();
@Accessor
double getY();
@Accessor
double getZ();
@Accessor
float getPower();
@Accessor
Entity getEntity();
}
@@ -1,5 +1,6 @@
package carpet.mixins;
import carpet.helpers.OptimizedExplosion;
import carpet.settings.CarpetSettings;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.explosion.Explosion;
@@ -18,6 +19,28 @@ public abstract class ExplosionMixin
@Shadow
@Final
private List<BlockPos> affectedBlocks;
@Inject(method = "collectBlocksAndDamageEntities", at = @At("HEAD"),
cancellable = true)
private void onExplosionA(CallbackInfo ci)
{
if (CarpetSettings.optimizedTNT)
{
OptimizedExplosion.doExplosionA((Explosion) (Object) this);
ci.cancel();
}
}
@Inject(method = "affectWorld", at = @At("HEAD"),
cancellable = true)
private void onExplosionB(boolean spawnParticles, CallbackInfo ci)
{
if (CarpetSettings.optimizedTNT)
{
OptimizedExplosion.doExplosionB((Explosion) (Object) this, spawnParticles);
ci.cancel();
}
}
@Inject(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
target = "Ljava/util/List;addAll(Ljava/util/Collection;)Z"))
@@ -1,5 +1,6 @@
package carpet.mixins;
import carpet.fakes.TntEntityInterface;
import carpet.settings.CarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
@@ -7,7 +8,9 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.TntEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -15,15 +18,28 @@ import carpet.logging.LoggerRegistry;
import carpet.logging.logHelpers.TNTLogHelper;
@Mixin(TntEntity.class)
public abstract class TntEntityMixin extends Entity
public abstract class TntEntityMixin extends Entity implements TntEntityInterface
{
@Shadow private int fuseTimer;
private TNTLogHelper logHelper;
private boolean mergeBool = false;
private int mergedTNT = 1;
public TntEntityMixin(EntityType<?> entityType_1, World world_1)
{
super(entityType_1, world_1);
}
@Inject(method = "<init>(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/LivingEntity;)V",
at = @At("RETURN"))
private void modifyTNTAngle(World world, double x, double y, double z, LivingEntity entity, CallbackInfo ci)
{
if (CarpetSettings.hardcodeTNTangle != -1)
setVelocity(-Math.sin(CarpetSettings.hardcodeTNTangle) * 0.02, 0.2, -Math.cos(CarpetSettings.hardcodeTNTangle) * 0.02);
}
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN"))
private void initTNTLoggerPrime(EntityType<? extends TntEntity> entityType_1, World world_1, CallbackInfo ci)
{
@@ -57,5 +73,55 @@ public abstract class TntEntityMixin extends Entity
{
if (LoggerRegistry.__tnt && logHelper != null)
logHelper.onExploded(getX(), getY(), getZ());
if (mergedTNT > 1)
for (int i = 0; i < mergedTNT - 1; i++)
this.world.createExplosion(this, this.getX(), this.getY() + (double)(this.getHeight() / 16.0F),
this.getZ(),
4.0F,
Explosion.DestructionType.BREAK);
}
@Inject(method = "tick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/entity/TntEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V",
ordinal = 2))
private void tryMergeTnt(CallbackInfo ci)
{
// Merge code for combining tnt into a single entity if they happen to exist in the same spot, same fuse, no motion CARPET-XCOM
if(CarpetSettings.mergeTNT){
Vec3d velocity = getVelocity();
if(!world.isClient && mergeBool && velocity.x == 0 && velocity.y == 0 && velocity.z == 0){
mergeBool = false;
for(Entity entity : world.getEntities(this, this.getBoundingBox())){
if(entity instanceof TntEntity && !entity.removed){
TntEntity entityTNTPrimed = (TntEntity)entity;
Vec3d tntVelocity = entityTNTPrimed.getVelocity();
if(tntVelocity.x == 0 && tntVelocity.y == 0 && tntVelocity.z == 0
&& this.getX() == entityTNTPrimed.getX() && this.getZ() == entityTNTPrimed.getZ() && this.getY() == entityTNTPrimed.getY()
&& this.fuseTimer == entityTNTPrimed.getFuseTimer()){
mergedTNT += ((TntEntityInterface) entityTNTPrimed).getMergedTNT();
entityTNTPrimed.remove();
}
}
}
}
}
}
@Inject(method = "tick", at = @At(value = "FIELD",
target = "Lnet/minecraft/entity/TntEntity;fuseTimer:I",
ordinal = 0))
private void setMergeable(CallbackInfo ci)
{
// Merge code, merge only tnt that have had a chance to move CARPET-XCOM
Vec3d velocity = getVelocity();
if(!world.isClient && (velocity.y != 0 || velocity.x != 0 || velocity.z != 0)){
mergeBool = true;
}
}
@Override
public int getMergedTNT() {
return mergedTNT;
}
}