-
Notifications
You must be signed in to change notification settings - Fork 3
Updates #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Updates #7
Changes from 5 commits
f27130f
6424a44
cee9c99
9c46f5a
88a98bd
bdf7846
7c65a79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,32 +24,151 @@ | |
|
|
||
| package org.fountainmc.forge.mixin.entity; | ||
|
|
||
| import com.google.common.collect.ImmutableCollection; | ||
| import com.google.common.collect.ImmutableList; | ||
| import net.minecraft.command.ICommandSender; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import org.fountainmc.api.entity.Entity; | ||
| import org.fountainmc.api.world.Location; | ||
| import org.fountainmc.api.world.World; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.*; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Mixin(net.minecraft.entity.Entity.class) | ||
| public abstract class MixinEntity implements Entity { | ||
| @Implements(@Interface(iface = Entity.class, prefix = "entity$")) | ||
| public abstract class MixinEntity implements Entity, ICommandSender { | ||
|
|
||
| @Shadow public boolean onGround; | ||
| @Shadow public float rotationPitch; | ||
| @Shadow public float rotationYaw; | ||
|
|
||
| @Shadow | ||
| public abstract BlockPos getPosition(); | ||
|
|
||
| @Shadow | ||
| public abstract net.minecraft.world.World getEntityWorld(); | ||
|
|
||
| @Shadow | ||
| public abstract void setPosition(double x, double y, double z); | ||
|
|
||
| @Shadow | ||
| public abstract List<net.minecraft.entity.Entity> shadow$getPassengers(); | ||
|
|
||
| @Shadow | ||
| public abstract void shadow$addPassenger(net.minecraft.entity.Entity passenger); | ||
|
||
|
|
||
| @Shadow | ||
| public abstract void removePassenger(net.minecraft.entity.Entity passenger); | ||
|
|
||
| @Override | ||
| public Location getLocation() { | ||
| return new Location((World) this.getEntityWorld(), | ||
| this.getPosition().getX(), this.getPosition().getY(), this.getPosition().getZ()); | ||
| } | ||
|
|
||
| @Override | ||
| public void teleport(Location destination) { | ||
| this.setPosition(destination.getX(), destination.getY(), | ||
| destination.getZ()); | ||
| } | ||
|
|
||
| @Override | ||
| public float getPitch() { | ||
| return this.rotationPitch; | ||
| } | ||
|
|
||
| @Override | ||
| public void setPitch(float pitch) { | ||
| this.rotationPitch = pitch; | ||
| } | ||
|
|
||
| @Override | ||
| public float getYaw() { | ||
| return this.rotationYaw; | ||
| } | ||
|
|
||
| @Override | ||
| public void setYaw(float yaw) { | ||
| this.rotationYaw = yaw; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOnGround() { | ||
| return this.onGround; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Entity getPrimaryPassenger() { | ||
| if (getPassengers().size() != 0) { | ||
| return getPassengers().get(0); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Intrinsic | ||
| @Nonnull | ||
| public ImmutableList<Entity> entity$getPassengers() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the entity$ if it's not intrinsic, or are you just missing intrinsic? |
||
| List entities = this.shadow$getPassengers(); | ||
|
||
| return ImmutableList.copyOf((List<Entity>) entities); | ||
| } | ||
|
|
||
| @Override | ||
| public void setPrimaryPassenger(Entity passenger) { | ||
| this.ejectPassenger(this.getPrimaryPassenger()); | ||
| ((net.minecraft.entity.Entity) passenger).startRiding(this.getCommandSenderEntity()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean addPassenger(Entity entity, boolean force) { | ||
| this.shadow$addPassenger((net.minecraft.entity.Entity) entity); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void ejectAll() { | ||
| this.getPassengers().forEach(this::ejectPassenger); | ||
| } | ||
|
|
||
| @Override | ||
| public void ejectPassenger(Entity passenger) { | ||
| passenger.leaveVehicle(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getMaximumPassengers() { | ||
| return this.shadow$getPassengers().size(); | ||
| } | ||
|
|
||
| @Override | ||
| public void dismountVehicle() { | ||
| if (this.shadow$getPassengers().size() != 0) { return; } | ||
| this.getPrimaryPassenger().leaveVehicle(); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Entity getVehicle() { | ||
| return (Entity) this.getCommandSenderEntity().getRidingEntity(); | ||
| } | ||
|
|
||
| @Override | ||
| public void leaveVehicle() { | ||
| (this.getCommandSenderEntity()).dismountRidingEntity(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the brackets? |
||
| } | ||
|
|
||
| @Override | ||
| public ImmutableCollection<Entity> getNearbyEntities(double distance) { | ||
| List<net.minecraft.entity.Entity> nmsEntities = this.getCommandSenderEntity().worldObj.getEntitiesWithinAABBExcludingEntity(this.getCommandSenderEntity(), this.getCommandSenderEntity().getEntityBoundingBox().expand(distance / 3, distance / 3, distance / 3)); | ||
| List<Entity> apiEntities = new ArrayList<>(); | ||
| for (net.minecraft.entity.Entity entity : nmsEntities) { | ||
| apiEntities.add((Entity) entity); | ||
| } | ||
| return ImmutableList.copyOf(apiEntities); | ||
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't collect imports using *.