-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
391 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/net/id/paradiselost/blocks/mechanical/LevitaRailBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.id.paradiselost.blocks.mechanical; | ||
|
||
import net.id.paradiselost.component.ParadiseLostComponents; | ||
import net.id.paradiselost.entities.ParadiseLostEntityExtensions; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.PoweredRailBlock; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.vehicle.AbstractMinecartEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Box; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class LevitaRailBlock extends PoweredRailBlock { | ||
|
||
public LevitaRailBlock(AbstractBlock.Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { | ||
if (!world.isClient) { | ||
List<AbstractMinecartEntity> list = this.getCarts(world, pos, AbstractMinecartEntity.class, e -> true); | ||
for (AbstractMinecartEntity cart : list) { | ||
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(cart); | ||
floatingComponent.startFloating(); | ||
ParadiseLostComponents.FLOATING_KEY.sync(cart); | ||
} | ||
} | ||
} | ||
|
||
private <T extends AbstractMinecartEntity> List<T> getCarts(World world, BlockPos pos, Class<T> entityClass, Predicate<Entity> entityPredicate) { | ||
return world.getEntitiesByClass(entityClass, this.getCartDetectionBox(pos), entityPredicate); | ||
} | ||
|
||
private Box getCartDetectionBox(BlockPos pos) { | ||
double radius = 0.4; | ||
return new Box( | ||
pos.getX() + radius, | ||
pos.getY(), | ||
pos.getZ() + radius, | ||
pos.getX() + 1 - radius, | ||
pos.getY() + 1 - radius, | ||
pos.getZ() + 1 - radius | ||
); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/net/id/paradiselost/client/rendering/particle/LevitaBloopParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package net.id.paradiselost.client.rendering.particle; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.particle.Particle; | ||
import net.minecraft.client.particle.ParticleFactory; | ||
import net.minecraft.client.particle.ParticleTextureSheet; | ||
import net.minecraft.client.particle.SpriteBillboardParticle; | ||
import net.minecraft.client.particle.SpriteProvider; | ||
import net.minecraft.client.particle.SuspendParticle; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.particle.SimpleParticleType; | ||
|
||
/* | ||
* Basically just a SuspendParticle, but that particle isn't public :I | ||
* These are bigger than normal suspend particles though | ||
*/ | ||
public class LevitaBloopParticle extends SpriteBillboardParticle { | ||
|
||
LevitaBloopParticle(ClientWorld clientWorld, double d, double e, double f, double g, double h, double i) { | ||
super(clientWorld, d, e, f, g, h, i); | ||
float j = this.random.nextFloat() * 0.1F + 0.2F; | ||
this.red = j; | ||
this.green = j; | ||
this.blue = j; | ||
this.setBoundingBoxSpacing(0.02F, 0.02F); | ||
this.scale = this.scale * (this.random.nextFloat() * 0.7F + 1.1F); | ||
this.velocityX *= 0.02F; | ||
this.velocityY *= 0.02F; | ||
this.velocityZ *= 0.02F; | ||
this.maxAge = (int)(20.0 / (Math.random() * 0.8 + 0.2)); | ||
} | ||
|
||
@Override | ||
public ParticleTextureSheet getType() { | ||
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE; | ||
} | ||
|
||
@Override | ||
public void move(double dx, double dy, double dz) { | ||
this.setBoundingBox(this.getBoundingBox().offset(dx, dy, dz)); | ||
this.repositionFromBoundingBox(); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
this.prevPosX = this.x; | ||
this.prevPosY = this.y; | ||
this.prevPosZ = this.z; | ||
if (this.maxAge-- <= 0) { | ||
this.markDead(); | ||
} else { | ||
this.move(this.velocityX, this.velocityY, this.velocityZ); | ||
this.velocityX *= 0.99; | ||
this.velocityY *= 0.99; | ||
this.velocityZ *= 0.99; | ||
} | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
public static class DefaultFactory implements ParticleFactory<SimpleParticleType> { | ||
private final SpriteProvider spriteProvider; | ||
|
||
public DefaultFactory(SpriteProvider spriteProvider) { | ||
this.spriteProvider = spriteProvider; | ||
} | ||
|
||
public Particle createParticle(SimpleParticleType simpleParticleType, ClientWorld clientWorld, double d, double e, double f, double g, double h, double i) { | ||
LevitaBloopParticle suspendParticle = new LevitaBloopParticle(clientWorld, d, e, f, g, h, i); | ||
suspendParticle.setColor(0.5F, 0.45F, 1.0F); | ||
suspendParticle.setSprite(this.spriteProvider); | ||
suspendParticle.setAlpha(1.0F - clientWorld.random.nextFloat() * 0.7F); | ||
suspendParticle.setMaxAge(suspendParticle.getMaxAge() / 2); | ||
return suspendParticle; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/net/id/paradiselost/component/FloatingComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.id.paradiselost.component; | ||
|
||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; | ||
|
||
public class FloatingComponent implements AutoSyncedComponent { | ||
|
||
private static final int FLOAT_SECONDS = 4; | ||
private boolean floating = false; | ||
private int floatTime = 0; | ||
|
||
@Override | ||
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { | ||
floating = tag.getBoolean("floating"); | ||
floatTime = tag.getInt("floatTime"); | ||
} | ||
|
||
@Override | ||
public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { | ||
tag.putBoolean("floating", floating); | ||
tag.putInt("floatTime", floatTime); | ||
} | ||
|
||
public boolean getFloating() { | ||
return floating; | ||
} | ||
|
||
public int getFloatTime() { | ||
return floatTime; | ||
} | ||
|
||
public void startFloating() { | ||
floating = true; | ||
floatTime = 20 * FLOAT_SECONDS; | ||
} | ||
|
||
public void tick() { | ||
floatTime--; | ||
if (floatTime == 0) { | ||
floating = false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/net/id/paradiselost/mixin/entity/AbstractMinecartEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.id.paradiselost.mixin.entity; | ||
|
||
import net.id.paradiselost.client.rendering.particle.ParadiseLostParticles; | ||
import net.id.paradiselost.component.ParadiseLostComponents; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.MovementType; | ||
import net.minecraft.entity.vehicle.AbstractMinecartEntity; | ||
import net.minecraft.entity.vehicle.VehicleEntity; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
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; | ||
|
||
@Mixin(AbstractMinecartEntity.class) | ||
public abstract class AbstractMinecartEntityMixin extends VehicleEntity { | ||
|
||
public AbstractMinecartEntityMixin(EntityType<?> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Shadow | ||
private boolean onRail; | ||
|
||
@Shadow | ||
protected abstract double getMaxSpeed(); | ||
|
||
@Inject(method = "moveOffRail", at = @At("HEAD"), cancellable = true) | ||
protected void moveOffRail(CallbackInfo ci) { | ||
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(this); | ||
if (!this.isOnGround() && floatingComponent.getFloating() && floatingComponent.getFloatTime() > 0) { | ||
double d = this.getMaxSpeed(); | ||
Vec3d vec3d = this.getVelocity(); | ||
this.setVelocity(MathHelper.clamp(vec3d.x, -d, d), 0, MathHelper.clamp(vec3d.z, -d, d)); | ||
this.move(MovementType.SELF, this.getVelocity()); | ||
// decrement | ||
floatingComponent.tick(); | ||
ParadiseLostComponents.FLOATING_KEY.sync(this); | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "tick", at = @At("HEAD")) | ||
public void tick(CallbackInfo ci) { | ||
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(this); | ||
if (this.getWorld().isClient && !this.onRail && floatingComponent.getFloating()) { | ||
var pos = this.getPos(); | ||
var rightParticlePos = pos.add(this.getVelocity().normalize().multiply(0.35F).rotateY(1.57F)); | ||
var leftParticlePos = pos.add(this.getVelocity().normalize().multiply(0.35F).rotateY(-1.57F)); | ||
this.getWorld().addParticle(ParadiseLostParticles.LEVITA_BLOOP, rightParticlePos.getX(), this.getY(), rightParticlePos.getZ(), 0, 0, 0); | ||
this.getWorld().addParticle(ParadiseLostParticles.LEVITA_BLOOP, leftParticlePos.getX(), this.getY(), leftParticlePos.getZ(), 0, 0, 0); | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/net/id/paradiselost/mixin/entity/EntityMixin.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/resources/assets/paradise_lost/blockstates/levita_rail.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"variants": { | ||
"powered=false,shape=ascending_east": { | ||
"model": "paradise_lost:block/levita_rail_raised_ne", | ||
"y": 90 | ||
}, | ||
"powered=false,shape=ascending_north": { | ||
"model": "paradise_lost:block/levita_rail_raised_ne" | ||
}, | ||
"powered=false,shape=ascending_south": { | ||
"model": "paradise_lost:block/levita_rail_raised_sw" | ||
}, | ||
"powered=false,shape=ascending_west": { | ||
"model": "paradise_lost:block/levita_rail_raised_sw", | ||
"y": 90 | ||
}, | ||
"powered=false,shape=east_west": { | ||
"model": "paradise_lost:block/levita_rail", | ||
"y": 90 | ||
}, | ||
"powered=false,shape=north_south": { | ||
"model": "paradise_lost:block/levita_rail" | ||
}, | ||
"powered=true,shape=ascending_east": { | ||
"model": "paradise_lost:block/levita_rail_on_raised_ne", | ||
"y": 90 | ||
}, | ||
"powered=true,shape=ascending_north": { | ||
"model": "paradise_lost:block/levita_rail_on_raised_ne" | ||
}, | ||
"powered=true,shape=ascending_south": { | ||
"model": "paradise_lost:block/levita_rail_on_raised_sw" | ||
}, | ||
"powered=true,shape=ascending_west": { | ||
"model": "paradise_lost:block/levita_rail_on_raised_sw", | ||
"y": 90 | ||
}, | ||
"powered=true,shape=east_west": { | ||
"model": "paradise_lost:block/levita_rail_on", | ||
"y": 90 | ||
}, | ||
"powered=true,shape=north_south": { | ||
"model": "paradise_lost:block/levita_rail_on" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/paradise_lost/models/block/levita_rail.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:block/rail_flat", | ||
"textures": { | ||
"rail": "paradise_lost:block/levita_rail" | ||
} | ||
} |
Oops, something went wrong.