Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 22, 2024
1 parent 2366dea commit 6dd650c
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.frozenblock.trailiertales.entity.Apparition;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
Expand All @@ -33,6 +35,11 @@ protected MapCodec<? extends EctoplasmBlock> codec() {
@Override
@NotNull
public VoxelShape getCollisionShape(@NotNull BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos, @NotNull CollisionContext collisionContext) {
if (collisionContext instanceof EntityCollisionContext entityCollisionContext) {
if (entityCollisionContext.getEntity() instanceof Apparition) {
return super.getCollisionShape(blockState, blockGetter, blockPos, collisionContext);
}
}
return COLLISION_SHAPE;
}

Expand Down
27 changes: 23 additions & 4 deletions src/main/java/net/frozenblock/trailiertales/entity/Apparition.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,40 @@ protected SoundEvent getAmbientSound() {
}

@Override
protected SoundEvent getHurtSound(DamageSource source) {
protected @NotNull SoundEvent getHurtSound(DamageSource source) {
return TTSounds.APPARITION_HURT;
}

@Override
protected SoundEvent getDeathSound() {
protected @NotNull SoundEvent getDeathSound() {
return TTSounds.APPARITION_DEATH;
}

@Override
protected @NotNull MovementEmission getMovementEmission() {
return MovementEmission.NONE;
}

@Override
public float getSoundVolume() {
return 0.75F;
}

@Override
public boolean onGround() {
return false;
}

@Override
public boolean isInWall() {
return false;
}

@Override
public void tick() {
this.noPhysics = true;
this.stuckSpeedMultiplier = Vec3.ZERO;
this.fallDistance = 0F;
super.tick();
this.noPhysics = false;
this.setNoGravity(true);
if (!this.level().isClientSide) {
this.tickTransparency();
Expand Down Expand Up @@ -640,6 +655,10 @@ protected void doPush(Entity entity) {
protected void pushEntities() {
}

@Override
public void push(Entity entity) {
}

public void spawnParticles(int count, ParticleOptions particleOptions) {
if (this.level() instanceof ServerLevel level) {
level.sendParticles(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.frozenblock.trailiertales.mixin.common.apparition;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.frozenblock.trailiertales.block.EctoplasmBlock;
import net.frozenblock.trailiertales.entity.Apparition;
import net.minecraft.world.level.BlockCollisions;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(BlockCollisions.class)
public class BlockCollisionsMixin {

@Shadow
@Final
private CollisionContext context;

@ModifyExpressionValue(
method = "computeNext",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/BlockGetter;getBlockState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;"
)
)
public BlockState trailierTales$modifyBlockStateForApparitions(BlockState original) {
if (this.context instanceof EntityCollisionContext entityCollisionContext) {
if (entityCollisionContext.getEntity() instanceof Apparition) {
return original.getBlock() instanceof EctoplasmBlock ? original : Blocks.AIR.defaultBlockState();
}
}

return original;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.frozenblock.trailiertales.mixin.common.apparition;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.frozenblock.trailiertales.entity.Apparition;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import java.util.List;

@Mixin(Entity.class)
public class EntityMixin {

@ModifyExpressionValue(
method = "collide",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;getEntityCollisions(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;)Ljava/util/List;"
)
)
private List<VoxelShape> trailierTales$noApparitionCollisions(List<VoxelShape> original) {
if (Entity.class.cast(this) instanceof Apparition) {
return List.of();
}

return original;
}

}
2 changes: 2 additions & 0 deletions src/main/resources/trailiertales.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"compatibilityLevel": "JAVA_21",
"plugin": "net.frozenblock.trailiertales.mixin.TTMixinPlugin",
"mixins": [
"common.apparition.BlockCollisionsMixin",
"common.apparition.EntityMixin",
"common.armor_stand.ArmorStandMixin",
"common.boat.BoatMixin",
"common.boat.ChestBoatMixin",
Expand Down

0 comments on commit 6dd650c

Please sign in to comment.