This commit is contained in:
gnembon committed 2019-05-11 11:20:56 -03:00
1 parent 71c07b63fd
commit 49118ce503
10 files changed
+98 -104

No files matched your search

@@ -1,9 +1,8 @@
package carpet.logging;
import carpet.CarpetSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.server.MinecraftServer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
import java.lang.reflect.Field;
import java.util.Arrays;
@@ -40,7 +39,7 @@ public class LoggerRegistry
registerLogger("tps", new HUDLogger("tps", null, null));
registerLogger("packets", new HUDLogger("packets", null, null));
registerLogger("counter",new HUDLogger("counter","white", Arrays.stream(EnumDyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("counter",new HUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", new HUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
}
@@ -136,7 +135,7 @@ public class LoggerRegistry
setAccess(logger);
}
public static void playerConnected(EntityPlayer player)
public static void playerConnected(PlayerEntity player)
{
for(Logger log: loggerRegistry.values() )
{
@@ -144,7 +143,7 @@ public class LoggerRegistry
}
}
public static void playerDisconnected(EntityPlayer player)
public static void playerDisconnected(PlayerEntity player)
{
for(Logger log: loggerRegistry.values() )
{
@@ -3,28 +3,28 @@ package carpet.logging.logHelpers;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.network.chat.BaseComponent;
import java.util.function.Supplier;
public class DamageReporter
{
private static ITextComponent[] verifyAndProduceMessage(String option, EntityPlayer player, Entity from, Entity to, Supplier<ITextComponent> messageFuture)
private static BaseComponent[] verifyAndProduceMessage(String option, PlayerEntity player, Entity from, Entity to, Supplier<BaseComponent> messageFuture)
{
if ("all".equalsIgnoreCase(option)
|| ("players".equalsIgnoreCase(option) && (from instanceof EntityPlayer || to instanceof EntityPlayer))
|| ("players".equalsIgnoreCase(option) && (from instanceof PlayerEntity || to instanceof PlayerEntity))
|| ("me".equalsIgnoreCase(option) && ( (from == player) || ( to == player) ) ))
{
return new ITextComponent[]{messageFuture.get()};
return new BaseComponent[]{messageFuture.get()};
}
return null;
}
public static boolean register_damage_attacker(Entity target, EntityLivingBase source, float amount)
public static boolean register_damage_attacker(Entity target, LivingEntity source, float amount)
{
if (!LoggerRegistry.__damage) return true;
LoggerRegistry.getLogger("damage").log( (option, player)->
@@ -37,27 +37,27 @@ public class DamageReporter
return true;
}
public static void register_damage(EntityLivingBase target, DamageSource source, float amount)
public static void register_damage(LivingEntity target, DamageSource source, float amount)
{
if (!LoggerRegistry.__damage) return;
if (source.isFireDamage() && (target.isImmuneToFire() ||
target.isPotionActive(MobEffects.FIRE_RESISTANCE)))
if (source.isFire() && (target.isFireImmune() ||
target.hasStatusEffect(StatusEffects.FIRE_RESISTANCE)))
return;
LoggerRegistry.getLogger("damage").log( (option, player)->
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
verifyAndProduceMessage(option, player, source.getSource(), target, () ->
Messenger.c(target.getDisplayName(),
"g receiving ",
String.format("r %.2f", amount),
String.format("g points of damage from %s", source.getDamageType()))
String.format("g points of damage from %s", source.getName()))
)
);
}
public static void register_final_damage(EntityLivingBase target, DamageSource source, float amount)
public static void register_final_damage(LivingEntity target, DamageSource source, float amount)
{
if (!LoggerRegistry.__damage) return;
LoggerRegistry.getLogger("damage").log( (option, player)->
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
verifyAndProduceMessage(option, player, source.getSource(), target, () ->
Messenger.c("g - total received ",
String.format("r %.2f", amount),
"g points of damage")
@@ -65,17 +65,17 @@ public class DamageReporter
);
}
public static void modify_damage(EntityLivingBase target, DamageSource source, float previous_amount, float final_amount, String component)
public static void modify_damage(LivingEntity target, DamageSource source, float previous_amount, float final_amount, String component)
{
if (!LoggerRegistry.__damage)
return;
if (previous_amount == final_amount)
return;
if (source.isFireDamage() && (target.isImmuneToFire() ||
target.isPotionActive(MobEffects.FIRE_RESISTANCE)))
if (source.isFire() && (target.isFireImmune() ||
target.hasStatusEffect(StatusEffects.FIRE_RESISTANCE)))
return;
LoggerRegistry.getLogger("damage").log( (option, player)->
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
verifyAndProduceMessage(option, player, source.getSource(), target, () ->
{
if (final_amount == 0.0f)
{
@@ -2,25 +2,25 @@ package carpet.logging.logHelpers;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.network.chat.BaseComponent;
public class KillLogHelper {
public static void onSweep(String name, int count)
{
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
LoggerRegistry.getLogger("kills").log( () -> new BaseComponent[]{
Messenger.c("g "+name+" smacked ","r "+count,"g entities with sweeping")});
}
public static void onNonSweepAttack(String name)
{
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
LoggerRegistry.getLogger("kills").log( () -> new BaseComponent[]{
Messenger.c("g "+name+" smacked ","r 1","g (no sweeping)")});
}
public static void onDudHit(String name)
{
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
LoggerRegistry.getLogger("kills").log( () -> new BaseComponent[]{
Messenger.c("g "+name+" dud hot = no one affected")});
}
}
@@ -2,7 +2,7 @@ package carpet.logging.logHelpers;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.network.chat.BaseComponent;
public class TNTLogHelper
{
@@ -26,11 +26,11 @@ public class TNTLogHelper
switch (option)
{
case "brief":
return new ITextComponent[]{Messenger.c(
return new BaseComponent[]{Messenger.c(
"l P ",Messenger.dblt("l",primedX,primedY,primedZ,primedAngle),
"r E ",Messenger.dblt("r",x, y, z))};
case "full":
return new ITextComponent[]{Messenger.c(
return new BaseComponent[]{Messenger.c(
"l P ",Messenger.dblf("l",primedX,primedY,primedZ,primedAngle),
"r E ",Messenger.dblf("r",x, y, z))};
}
@@ -4,7 +4,7 @@ import carpet.logging.Logger;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.network.chat.BaseComponent;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +39,7 @@ public class TrajectoryLogHelper
{
if (!doLog) return;
logger.log( (option) -> {
List<ITextComponent> comp = new ArrayList<>();
List<BaseComponent> comp = new ArrayList<>();
switch (option)
{
case "brief":
@@ -72,7 +72,7 @@ public class TrajectoryLogHelper
}
break;
}
return comp.toArray(new ITextComponent[0]);
return comp.toArray(new BaseComponent[0]);
});
doLog = false;
}
@@ -0,0 +1,12 @@
package carpet.mixins.spawnTracking;
import net.minecraft.util.WeightedPicker;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(WeightedPicker.Entry.class)
public interface WeightedPickerEntryMixin
{
@Accessor("weight")
int getWeight();
}
+7 -5
View File
@@ -1,6 +1,8 @@
package carpet.utils;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
@@ -199,15 +201,15 @@ public class BlockInfo
private static BaseComponent wander_chances(BlockPos pos, World worldIn)
{
MobEntityWithAi creature = new ZombiePigmanEntity(worldIn);
creature.onInitialSpawn(worldIn.getDifficultyForLocation(pos), null, null);
creature.setLocationAndAngles(pos.getX()+0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
MobEntityWithAi creature = new ZombiePigmanEntity(EntityType.ZOMBIE_PIGMAN, worldIn);
creature.initialize(worldIn, worldIn.getLocalDifficulty(pos), SpawnType.NATURAL, null, null);
creature.setPositionAndAngles(pos.getX()+0.5F, pos.getY(), pos.getZ()+0.5F, 0.0F, 0.0F);
WanderAroundGoal wander = new WanderAroundGoal(creature, 0.8D);
int success = 0;
for (int i=0; i<1000; i++)
{
Vec3d vec = PathfindingUtil.findRandomTarget(creature, 10, 7);
Vec3d vec = PathfindingUtil.findTarget(creature, 10, 7);
if (vec == null)
{
continue;
@@ -220,7 +222,7 @@ public class BlockInfo
int i;
for (i=1;i<30*20*60; i++) //*60 used to be 5 hours, limited to 30 mins
{
if (wander.shouldExecute())
if (wander.canStart())
{
break;
}
+38 -59
View File
@@ -6,8 +6,9 @@ import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.predicate.entity.EntityPredicates;
import carpet.mixins.spawnTracking.WeightedPickerEntryMixin;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;
import net.minecraft.network.chat.BaseComponent;
@@ -24,7 +25,6 @@ import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.SpawnHelper;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.OcelotEntity;
@@ -239,16 +239,18 @@ public class SpawnReporter
lst.add(Messenger.c(String.format("r Incorrect creature type: %s",creature_type_code)));
return lst;
}
Class<?> cls = typ.getBaseClass();// getCreatureClass();
Class<?> cls = typ.getDeclaringClass();// getBaseClass();// getCreatureClass();
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(typ))));
for (Entity entity : worldIn.loadedEntityList)
{
if ((!(entity instanceof LivingEntity) || !((LivingEntity)entity).isNoDespawnRequired()) && cls.isAssignableFrom(entity.getClass()))
{
lst.add(Messenger.c("w - ",
Messenger.tp("w", entity.posX, entity.posY, entity.posZ),"w : "+EntityType.getId(entity.getType())));
}
}
lst.add(Messenger.s(" <sorry, this list will be populated, once M figures out what counts>"));
//for (Entity entity : ((ServerWorld)worldIn).getEntities(...))
//{
// if ((!(entity instanceof LivingEntity) || !((LivingEntity)entity).isNoDespawnRequired()) && cls.isAssignableFrom(entity.getClass()))
// {
// lst.add(Messenger.c("w - ",
// Messenger.tp("w", entity.posX, entity.posY, entity.posZ),"w : "+EntityType.getId(entity.getType())));
// }
//}
if (lst.size()==1)
{
lst.add(Messenger.s(" - Empty."));
@@ -311,7 +313,7 @@ public class SpawnReporter
"w ' to enable"));
return report;
}
Long duration = (long) worldIn.getServer().getTickCounter() - track_spawns;
Long duration = (long) worldIn.getServer().getTicks() - track_spawns;
report.add(Messenger.c("bw --------------------"));
String simulated = mock_spawns?"[SIMULATED] ":"";
String location = (lower_spawning_limit != null)?String.format("[in (%d, %d, %d)x(%d, %d, %d)]",
@@ -358,20 +360,20 @@ public class SpawnReporter
public static void killEntity(LivingEntity entity)
{
if (entity.isPassenger())
if (entity.hasVehicle())
{
entity.getRidingEntity().remove();
entity.getVehicle().remove();
}
if (entity.isBeingRidden())
if (entity.hasPassengers())
{
for (Entity e: entity.getPassengers())
for (Entity e: entity.getPassengerList())
{
e.remove();
}
}
if (entity instanceof OcelotEntity)
{
for (Entity e: entity.getEntityWorld().getEntitiesWithinAABB(OcelotEntity.class, entity.getBoundingBox()))
for (Entity e: entity.getEntityWorld().getEntities(OcelotEntity.class, entity.getBoundingBox()))
{
e.remove();
}
@@ -384,7 +386,7 @@ public class SpawnReporter
List<BaseComponent> rep = new ArrayList<>();
int x = pos.getX(); int y = pos.getY(); int z = pos.getZ();
Chunk chunk = worldIn.getChunk(pos);
int lc = chunk.getTopBlockY(Heightmap.Type.LIGHT_BLOCKING, x, z) + 1;
int lc = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x, z) + 1;
String where = String.format((y >= lc) ? "%d blocks above it." : "%d blocks below it.", MathHelper.abs(y-lc));
if (y == lc) where = "right at it.";
rep.add(Messenger.s(String.format("Maximum spawn Y value for (%+d, %+d) is %d. You are "+where, x, z, lc )));
@@ -395,17 +397,17 @@ public class SpawnReporter
List<Biome.SpawnEntry> lst = ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(enumcreaturetype, pos);
if (lst != null && !lst.isEmpty())
{
for (Biome.SpawnEntry SpawnListEntry animal : lst)
for (Biome.SpawnEntry spawnEntry : lst)
{
boolean canspawn = SpawnHelper.canCreatureTypeSpawnAtLocation(SpawnRestriction.getPlacementType(animal.entityType), worldIn, pos, animal.entityType);
boolean canspawn = SpawnHelper.canSpawn(SpawnRestriction.getLocation(spawnEntry.type), worldIn, pos, spawnEntry.type);
int will_spawn = -1;
boolean fits = false;
boolean fits1 = false;
LivingEntity entityliving;
MobEntity mob;
try
{
entityliving = animal.entityType.create(worldIn);
mob = (MobEntity) spawnEntry.type.create(worldIn);
}
catch (Exception exception)
{
@@ -423,19 +425,19 @@ public class SpawnReporter
{
float f = (float)x + 0.5F;
float f1 = (float)z + 0.5F;
entityliving.setLocationAndAngles((double)f, (double)y, (double)f1, worldIn.rand.nextFloat() * 360.0F, 0.0F);
fits1 = entityliving.isNotColliding();
mob.setPositionAndAngles((double)f, (double)y, (double)f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
fits1 = worldIn.doesNotCollide(mob);
for (int i = 0; i < 20; ++i)
{
if (entityliving.canSpawn(worldIn, false))
if (mob.canSpawn(worldIn, SpawnType.NATURAL))
{
will_spawn += 1;
}
}
entityliving.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityliving)), null, null);
mob.initialize(worldIn, worldIn.getLocalDifficulty(new BlockPos(mob)), SpawnType.NATURAL, null, null);
// the code invokes onInitialSpawn after getCanSpawHere
fits = fits1 && entityliving.isNotColliding();
fits = fits1 && worldIn.doesNotCollide(mob);
if (fits)
{
fits_true = true;
@@ -445,11 +447,11 @@ public class SpawnReporter
fits_false = true;
}
killEntity(entityliving);
killEntity(mob);
try
{
entityliving = animal.entityType.create(worldIn);
mob = (MobEntity) spawnEntry.type.create(worldIn);
}
catch (Exception exception)
{
@@ -459,14 +461,14 @@ public class SpawnReporter
}
}
String creature_name = Registry.ENTITY_TYPE.getKey(entityliving.getType()).toString().replaceFirst("minecraft:","");
String pack_size = String.format("%d", entityliving.getMaxSpawnedInChunk());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
int weight = animal.getItemWeight();
String creature_name = Registry.ENTITY_TYPE.getId(mob.getType()).toString().replaceFirst("minecraft:","");
String pack_size = String.format("%d", mob.getLimitPerChunk());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
int weight = ((WeightedPickerEntryMixin) spawnEntry).getWeight();
if (canspawn)
{
String c = (fits_true && will_spawn>0)?"e":"gi";
rep.add(Messenger.c(
String.format("%s %s: %s (%d:%d-%d/%d), can: ",c,type_code,creature_name,weight,animal.minGroupCount, animal.maxGroupCount, entityliving.getMaxSpawnedInChunk()),
String.format("%s %s: %s (%d:%d-%d/%d), can: ",c,type_code,creature_name,weight,spawnEntry.minGroupSize, spawnEntry.maxGroupSize, mob.getLimitPerChunk()),
"l YES",
c+" , fit: ",
((fits_true && fits_false)?"y YES and NO":(fits_true?"l YES":"r NO")),
@@ -476,35 +478,12 @@ public class SpawnReporter
}
else
{
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ",type_code,creature_name,weight,animal.minGroupCount, animal.maxGroupCount, entityliving.getMaxSpawnedInChunk()), "n NO"));
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ",type_code,creature_name,weight,spawnEntry.minGroupSize, spawnEntry.maxGroupSize, mob.getLimitPerChunk()), "n NO"));
}
killEntity(entityliving);
killEntity(mob);
}
}
}
return rep;
}
public static boolean check_player_within_spawning_range(World worldServerIn, float x, float y, float z)
{
for (int i = 0; i < worldServerIn.playerEntities.size(); ++i)
{
PlayerEntity entityplayer = worldServerIn.playerEntities.get(i);
if (EntityPredicates.NOT_SPECTATING.test(entityplayer))
{
double d0 = entityplayer.getDistanceSq(x, y, z);
if ( d0 > 24.0*24.0 && d0 < 128.0*128.0)
{
return true;
}
}
}
return false;
}
}
+4 -3
View File
@@ -63,7 +63,8 @@ public class WoolTool
break;
case YELLOW:
if (CarpetSettings.getBool("commandInfo"))
EntityInfo.issue_entity_info(placer);
Messenger.m(placer, "r use data get entity command");
//EntityInfo.issue_entity_info(placer);
break;
case GREEN:
if (CarpetSettings.getBool("hopperCounters"))
@@ -94,8 +95,8 @@ public class WoolTool
public static DyeColor getWoolColorAtPosition(World worldIn, BlockPos pos)
{
BlockState state = worldIn.getBlockState(pos);
if (state.getMaterial() != Material.CLOTH || !state.isFullCube())
if (state.getMaterial() != Material.WOOL || !state.isSimpleFullBlock(worldIn, pos))
return null;
return Material2Dye.get(state.getMaterialColor(worldIn, pos));
return Material2Dye.get(state.getTopMaterialColor(worldIn, pos));
}
}