This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
40 additions
and
58 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
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: 2 additions & 4 deletions
6
...isionslib/client/CollisionsLibClient.java → ...ee/collisionslib/CollisionsLibClient.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
6 changes: 0 additions & 6 deletions
6
src/main/java/amymialee/collisionslib/client/LivingEntityAccessor.java
This file was deleted.
Oops, something went wrong.
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: 16 additions & 42 deletions
58
src/main/java/amymialee/collisionslib/mixin/LivingEntityMixin.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 |
---|---|---|
@@ -1,74 +1,48 @@ | ||
package amymialee.collisionslib.mixin; | ||
|
||
import amymialee.collisionslib.client.LivingEntityAccessor; | ||
import amymialee.collisionslib.CollisionsLib; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.data.DataTracker; | ||
import net.minecraft.entity.data.TrackedData; | ||
import net.minecraft.entity.data.TrackedDataHandlerRegistry; | ||
import net.minecraft.entity.attribute.DefaultAttributeContainer; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.vehicle.BoatEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(LivingEntity.class) | ||
public abstract class LivingEntityMixin extends Entity implements LivingEntityAccessor { | ||
@Unique private static final TrackedData<Boolean> INTANGIBLE; | ||
|
||
public LivingEntityMixin(EntityType<?> type, World world) { | ||
super(type, world); | ||
public abstract class LivingEntityMixin extends Entity { | ||
protected LivingEntityMixin(EntityType<? extends LivingEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject(method = "pushAway", at = @At("HEAD"), cancellable = true) | ||
protected void pushAway(Entity entity, CallbackInfo ci) { | ||
if (entity instanceof LivingEntity && ((LivingEntityAccessor) entity).isIntangible()) { | ||
if (entity instanceof LivingEntity && (CollisionsLib.getTangibility(((LivingEntity) ((Object) this))) || CollisionsLib.getTangibility((LivingEntity) entity))) { | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Unique | ||
public boolean collidesWith(Entity other) { | ||
return !this.isIntangible() && BoatEntity.canCollide(this, other); | ||
if (other instanceof LivingEntity) { | ||
return (this.isCollidable() && other.isCollidable()); | ||
} | ||
return other.isCollidable() && !this.isConnectedThroughVehicle(other); | ||
} | ||
|
||
@Unique | ||
public boolean isCollidable() { | ||
return !isIntangible(); | ||
} | ||
|
||
@Inject(method = "initDataTracker", at = @At("TAIL")) | ||
protected void initDataTracker(CallbackInfo ci) { | ||
this.getDataTracker().startTracking(INTANGIBLE, false); | ||
} | ||
|
||
@Inject(method = "writeCustomDataToNbt", at = @At("HEAD")) | ||
public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { | ||
nbt.putBoolean("intangible", this.getDataTracker().get(INTANGIBLE)); | ||
} | ||
|
||
@Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) | ||
public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { | ||
this.getDataTracker().set(INTANGIBLE, nbt.getBoolean("intangible")); | ||
} | ||
|
||
@Unique | ||
@Override | ||
public boolean isIntangible() { | ||
return this.getDataTracker().get(INTANGIBLE); | ||
} | ||
|
||
@Unique | ||
@Override | ||
public void setIntangible(boolean intangible) { | ||
this.getDataTracker().set(INTANGIBLE, intangible); | ||
return CollisionsLib.getTangibility(((LivingEntity) ((Object) this))); | ||
} | ||
|
||
static { | ||
INTANGIBLE = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.BOOLEAN); | ||
@Inject(method = "createLivingAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN")) | ||
private static void addAttributes(final CallbackInfoReturnable<DefaultAttributeContainer.Builder> info) { | ||
info.getReturnValue().add(CollisionsLib.TANGIBLE); | ||
} | ||
} |
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