Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The [Minecraft Forge] implementation of the [FountainAPI], licensed under the MI

## Cloning

- SSH: `git clone git@github.com:FountainMC/FountainForge.git`
- HTTPS: `git clone https://github.com/FountainMC/FountainForge.git`
- SSH: `git clone --recursive git@github.com:FountainMC/FountainForge.git`
- HTTPS: `git clone --recursive https://github.com/FountainMC/FountainForge.git`

## Building

Expand Down
120 changes: 117 additions & 3 deletions src/main/java/org/fountainmc/forge/mixin/entity/MixinEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,146 @@

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.*;
Copy link
Copy Markdown
Contributor

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 *.


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 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() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

return ImmutableList.copyOf((List<Entity>)((List) this.shadow$getPassengers()));
Copy link
Copy Markdown
Contributor

@jamierocks jamierocks Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother casting to List<Entity>

}

@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.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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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));
return ImmutableList.copyOf(((List<Entity>)((List) nmsEntities)));
Copy link
Copy Markdown
Contributor

@jamierocks jamierocks Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother casting to List<Entity>

}

}