Fixed clouds, mostly

This commit is contained in:
Sollace 2020-06-01 20:35:47 +02:00
parent 2db782422b
commit b5aca42ba6
5 changed files with 88 additions and 55 deletions

View file

@ -26,14 +26,14 @@ public class CloudEntityRenderer extends MobEntityRenderer<CloudEntity, CloudEnt
} }
@Override @Override
public void render(CloudEntity entity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) { public void render(CloudEntity entity, float f, float g, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i) {
if (entity.removed) { if (entity.removed) {
return; return;
} }
matrixStack.push(); matrices.push();
matrixStack.translate(0, -entity.getHeight()/entity.getCloudSize() + 0.3F, 0); matrices.translate(0, -entity.getHeight() + 0.3F, 0);
//GlStateManager.disableLighting(); //GlStateManager.disableLighting();
//GlStateManager.enableBlend(); //GlStateManager.enableBlend();
@ -44,13 +44,13 @@ public class CloudEntityRenderer extends MobEntityRenderer<CloudEntity, CloudEnt
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
super.render(entity, f, g, matrixStack, vertexConsumerProvider, i); super.render(entity, f, g, matrices, vertexConsumerProvider, i);
//GlStateManager.disableBlend(); //GlStateManager.disableBlend();
//GlStateManager.enableLighting(); //GlStateManager.enableLighting();
//GlStateManager.color4f(1, 1, 1, 1); //GlStateManager.color4f(1, 1, 1, 1);
matrixStack.pop(); matrices.pop();
} }
@Override @Override

View file

@ -13,7 +13,7 @@ public final class RenderLayers extends RenderLayer {
super(name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, translucent, startAction, endAction); super(name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, translucent, startAction, endAction);
} }
private static final RenderLayer MAGIC = RenderLayer.of("mlp_magic_glow", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL, 7, 256, RenderLayer.MultiPhaseParameters.builder() private static final RenderLayer MAGIC = of("mlp_magic_glow", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL, 7, 256, RenderLayer.MultiPhaseParameters.builder()
.texture(NO_TEXTURE) .texture(NO_TEXTURE)
.writeMaskState(COLOR_MASK) .writeMaskState(COLOR_MASK)
.transparency(LIGHTNING_TRANSPARENCY) .transparency(LIGHTNING_TRANSPARENCY)
@ -22,26 +22,26 @@ public final class RenderLayers extends RenderLayer {
.build(false)); .build(false));
public static RenderLayer entityNoLighting(Identifier tex) { public static RenderLayer entityNoLighting(Identifier tex) {
return RenderLayer.of("entity_cutout_no_cull_no_lighting", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, false, RenderLayer.MultiPhaseParameters.builder() return of("entity_cutout_no_cull_no_lighting", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, false, RenderLayer.MultiPhaseParameters.builder()
.texture(new RenderPhase.Texture(tex, false, false)) .texture(new RenderPhase.Texture(tex, false, false))
.transparency(RenderLayer.NO_TRANSPARENCY) .transparency(NO_TRANSPARENCY)
.diffuseLighting(RenderLayer.ENABLE_DIFFUSE_LIGHTING) .diffuseLighting(ENABLE_DIFFUSE_LIGHTING)
.alpha(RenderLayer.ONE_TENTH_ALPHA) .alpha(ONE_TENTH_ALPHA)
.cull(RenderLayer.DISABLE_CULLING) .cull(DISABLE_CULLING)
.lightmap(RenderLayer.DISABLE_LIGHTMAP) .lightmap(DISABLE_LIGHTMAP)
.overlay(RenderLayer.ENABLE_OVERLAY_COLOR) .overlay(ENABLE_OVERLAY_COLOR)
.build(true)); .build(true));
} }
public static RenderLayer cloud(Identifier tex) { public static RenderLayer cloud(Identifier tex) {
return RenderLayer.of("cloud", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, false, RenderLayer.MultiPhaseParameters.builder() return of("cloud", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, false, RenderLayer.MultiPhaseParameters.builder()
.texture(new RenderPhase.Texture(tex, false, false)) .texture(new RenderPhase.Texture(tex, false, false))
.transparency(RenderLayer.TRANSLUCENT_TRANSPARENCY) .transparency(TRANSLUCENT_TRANSPARENCY)
.diffuseLighting(RenderLayer.ENABLE_DIFFUSE_LIGHTING) .diffuseLighting(ENABLE_DIFFUSE_LIGHTING)
.alpha(RenderLayer.ONE_TENTH_ALPHA) .alpha(ONE_TENTH_ALPHA)
.cull(RenderLayer.DISABLE_CULLING) .lightmap(DISABLE_LIGHTMAP)
.lightmap(RenderLayer.DISABLE_LIGHTMAP) .overlay(DISABLE_OVERLAY_COLOR)
.overlay(RenderLayer.ENABLE_OVERLAY_COLOR) .cull(DISABLE_CULLING)
.build(true)); .build(true));
} }

View file

@ -68,6 +68,8 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
private static final TrackedData<Boolean> STATIONARY = DataTracker.registerData(CloudEntity.class, TrackedDataHandlerRegistry.BOOLEAN); private static final TrackedData<Boolean> STATIONARY = DataTracker.registerData(CloudEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
public static final EntityDimensions BASE_DIMENSIONS = EntityDimensions.changing(0.6f, 0.6f);
protected double targetAltitude; protected double targetAltitude;
protected int directionX; protected int directionX;
@ -75,6 +77,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
public CloudEntity(EntityType<? extends CloudEntity> type, World world) { public CloudEntity(EntityType<? extends CloudEntity> type, World world) {
super(type, world); super(type, world);
inanimate = true;
ignoreCameraFrustum = true; ignoreCameraFrustum = true;
targetAltitude = getRandomFlyingHeight(); targetAltitude = getRandomFlyingHeight();
} }
@ -355,7 +358,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
Vec3d vel = getVelocity(); Vec3d vel = getVelocity();
setVelocity(vel.x, vel.y - 0.002 + (Math.signum(distance) * 0.699999988079071D - vel.y) * 0.10000000149011612D, vel.z); setVelocity(vel.x, vel.y + (Math.signum(distance) * 0.699999988079071D - vel.y) * 0.10000000149011612D, vel.z);
} }
} }
} }
@ -364,10 +367,7 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
float a = getMaximumFlyingHeight(); float a = getMaximumFlyingHeight();
float b = getMinimumFlyingHeight(); float b = getMinimumFlyingHeight();
float min = Math.min(a, b); return MathHelper.lerp(world.random.nextFloat(), Math.min(a, b), Math.max(a, b));
float max = Math.max(a, b);
return min + world.random.nextFloat() * (max - min);
} }
protected float getMinimumFlyingHeight() { protected float getMinimumFlyingHeight() {
@ -461,13 +461,13 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
} }
super.onDeath(s); super.onDeath(s);
clearItemFloatingState(); //clearItemFloatingState();
} }
@Override @Override
public void remove() { public void remove() {
super.remove(); super.remove();
clearItemFloatingState(); //clearItemFloatingState();
} }
//@FUF(reason = "There is no TickEvent.EntityTickEvent. Waiting on mixins...") //@FUF(reason = "There is no TickEvent.EntityTickEvent. Waiting on mixins...")
@ -533,7 +533,8 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
if (!isConnectedThroughVehicle(entity) && floatStrength > 0) { if (!isConnectedThroughVehicle(entity) && floatStrength > 0) {
double boundModifier = entity.fallDistance > 80 ? 80 : MathHelper.floor(entity.fallDistance * 10) / 10; double bounceModifier = entity.fallDistance > 80 ? 80 : MathHelper.floor(entity.fallDistance * 10) / 10;
entity.onGround = true; entity.onGround = true;
@ -542,7 +543,15 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
double motionY = motion.y; double motionY = motion.y;
double motionZ = motion.z; double motionZ = motion.z;
motionY += (((floatStrength > 2 ? 1 : floatStrength/2) * 0.699999998079071D) - motionY + boundModifier * 0.7) * 0.10000000149011612D; if (motionY <= 0) {
motionY += (((floatStrength > 2 ? 1 : floatStrength/2) * 0.699999998079071D) - motionY + bounceModifier * 0.7) * 0.10000000149011612D;
motionY = Math.min(0.1F, motionY);
if (motionY < 0.002F) {
motionY = 0.001;
}
}
if (!getStationary()) { if (!getStationary()) {
motionX += ((motionX - motionX) / getCloudSize()) - 0.002F; motionX += ((motionX - motionX) / getCloudSize()) - 0.002F;
} }
@ -551,12 +560,9 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
spawnThunderbolt(getBlockPos()); spawnThunderbolt(getBlockPos());
} }
// @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...")
if (getStationary() && entity instanceof ItemEntity) { if (getStationary() && entity instanceof ItemEntity) {
motionX /= 8; motionX /= 8;
motionZ /= 8; motionZ /= 8;
motionY /= 16;
entity.setNoGravity(true);
} }
entity.setVelocity(motionX, motionY, motionZ); entity.setVelocity(motionX, motionY, motionZ);
@ -685,13 +691,17 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, InAnimate
} }
@Override @Override
public EntityDimensions getDimensions(EntityPose pose) { public float getScaleFactor() {
return super.getDimensions(pose).scaled(getCloudSize()); return getCloudSize();
} }
@Override
public EntityDimensions getDimensions(EntityPose pose) {
return EntityDimensions.changing(3, 0.5F).scaled(getScaleFactor()); // super.getDimensions(pose);
}
public void setCloudSize(int val) { public void setCloudSize(int val) {
val = Math.max(1, val); dataTracker.set(SCALE, Math.max(1, val));
dataTracker.set(SCALE, val);
calculateDimensions(); calculateDimensions();
} }
} }

View file

@ -1,6 +1,5 @@
package com.minelittlepony.unicopia.entity; package com.minelittlepony.unicopia.entity;
import com.google.common.collect.Lists;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -11,13 +10,15 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem; import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.RayTraceContext;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ConstructionCloudEntity extends CloudEntity { public class ConstructionCloudEntity extends CloudEntity {
@ -70,14 +71,23 @@ public class ConstructionCloudEntity extends CloudEntity {
float ticks = mc.getTickDelta(); float ticks = mc.getTickDelta();
Vec3d eye = player.getCameraPosVec(ticks); Vec3d start = player.getCameraPosVec(ticks);
Vec3d look = player.getOppositeRotationVector(ticks); Vec3d rotation = player.getRotationVec(ticks);
Vec3d ray = eye.add(look.x * distance, look.y * distance, look.z * distance); Vec3d end = start.add(rotation.x * distance, rotation.y * distance, rotation.z * distance);
float s = 0.5F; Box box = getBoundingBox().expand(3);
Box bounds = getBoundingBox().shrink(0, s, 0).shrink(0, -s, 0);
BlockHitResult hit = Box.rayTrace(Lists.newArrayList(bounds), eye, ray, BlockPos.ORIGIN); RayTraceContext ctx = new RayTraceContext(start, end, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, player);
BlockHitResult hit = BlockView.rayTrace(ctx, (c, pos) -> {
if (box.contains(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)) {
return new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true);
}
return null;
}, c -> {
return null;
});
if (hit != null) { if (hit != null) {
Direction direction = hit.getSide(); Direction direction = hit.getSide();

View file

@ -18,21 +18,34 @@ import net.minecraft.world.biome.PlainsBiome;
import net.minecraft.world.biome.RiverBiome; import net.minecraft.world.biome.RiverBiome;
public interface UEntities { public interface UEntities {
EntityType<SpellbookEntity> SPELLBOOK = register("spellbook", FabricEntityTypeBuilder.create(EntityCategory.MISC, SpellbookEntity::new).size(EntityDimensions.changing(0.6f, 0.6f))); EntityType<SpellbookEntity> SPELLBOOK = register("spellbook", FabricEntityTypeBuilder.create(EntityCategory.MISC, SpellbookEntity::new)
EntityType<SpellcastEntity> MAGIC_SPELL = register("magic_spell", FabricEntityTypeBuilder.create(EntityCategory.MISC, SpellcastEntity::new).size(EntityDimensions.changing(0.6F, 0.25F))); .size(EntityDimensions.changing(0.6F, 0.6F)));
EntityType<CloudEntity> CLOUD = register("cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, CloudEntity::new)); EntityType<SpellcastEntity> MAGIC_SPELL = register("magic_spell", FabricEntityTypeBuilder.create(EntityCategory.MISC, SpellcastEntity::new)
EntityType<WildCloudEntity> WILD_CLOUD = register("wild_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, WildCloudEntity::new)); .size(EntityDimensions.changing(0.6F, 0.25F)));
EntityType<RacingCloudEntity> RACING_CLOUD = register("racing_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, RacingCloudEntity::new)); EntityType<CloudEntity> CLOUD = register("cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, CloudEntity::new)
EntityType<ConstructionCloudEntity> CONSTRUCTION_CLOUD = register("construction_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, ConstructionCloudEntity::new)); .size(CloudEntity.BASE_DIMENSIONS));
EntityType<WildCloudEntity> WILD_CLOUD = register("wild_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, WildCloudEntity::new)
.size(CloudEntity.BASE_DIMENSIONS));
EntityType<RacingCloudEntity> RACING_CLOUD = register("racing_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, RacingCloudEntity::new)
.size(CloudEntity.BASE_DIMENSIONS));
EntityType<ConstructionCloudEntity> CONSTRUCTION_CLOUD = register("construction_cloud", FabricEntityTypeBuilder.create(EntityCategory.CREATURE, ConstructionCloudEntity::new)
.size(CloudEntity.BASE_DIMENSIONS));
EntityType<RainbowEntity> RAINBOW = register("rainbow", FabricEntityTypeBuilder.create(EntityCategory.AMBIENT, RainbowEntity::new)); EntityType<RainbowEntity> RAINBOW = register("rainbow", FabricEntityTypeBuilder.create(EntityCategory.AMBIENT, RainbowEntity::new)
.size(EntityDimensions.fixed(1, 1)));
EntityType<CuccoonEntity> CUCCOON = register("cuccoon", FabricEntityTypeBuilder.create(EntityCategory.MISC, CuccoonEntity::new).size(EntityDimensions.changing(1.5F, 1.6F))); EntityType<CuccoonEntity> CUCCOON = register("cuccoon", FabricEntityTypeBuilder.create(EntityCategory.MISC, CuccoonEntity::new)
.size(EntityDimensions.changing(1.5F, 1.6F)));
EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", FabricEntityTypeBuilder.create(EntityCategory.AMBIENT, ButterflyEntity::new).size(EntityDimensions.fixed(1, 1))); EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", FabricEntityTypeBuilder.create(EntityCategory.AMBIENT, ButterflyEntity::new)
.size(EntityDimensions.fixed(1, 1)));
EntityType<ProjectileEntity> THROWN_ITEM = register("thrown_item", FabricEntityTypeBuilder.<ProjectileEntity>create(EntityCategory.MISC, ProjectileEntity::new).trackable(100, 2)); EntityType<ProjectileEntity> THROWN_ITEM = register("thrown_item", FabricEntityTypeBuilder.<ProjectileEntity>create(EntityCategory.MISC, ProjectileEntity::new)
EntityType<SpearEntity> THROWN_SPEAR = register("thrown_spear", FabricEntityTypeBuilder.<SpearEntity>create(EntityCategory.MISC, SpearEntity::new).trackable(100, 2)); .trackable(100, 2)
.size(EntityDimensions.fixed(0.25F, 0.25F)));
EntityType<SpearEntity> THROWN_SPEAR = register("thrown_spear", FabricEntityTypeBuilder.<SpearEntity>create(EntityCategory.MISC, SpearEntity::new)
.trackable(100, 2)
.size(EntityDimensions.fixed(0.6F, 0.6F)));
static <T extends Entity> EntityType<T> register(String name, FabricEntityTypeBuilder<T> builder) { static <T extends Entity> EntityType<T> register(String name, FabricEntityTypeBuilder<T> builder) {
return Registry.register(Registry.ENTITY_TYPE, new Identifier("unicopia", name), builder.build()); return Registry.register(Registry.ENTITY_TYPE, new Identifier("unicopia", name), builder.build());