Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
125 changes: 122 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,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.*;
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 shadow$addPassenger(net.minecraft.entity.Entity passenger);
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 shadow$ prefix?


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

List entities = this.shadow$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 need for this field?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IDE errors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You sure get a lot of IDE errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work unless the shadow method has a List return type without a generic. Would Mixin register it correctly?

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.

Just cast to a List

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();
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));
List<Entity> apiEntities = new ArrayList<>();
for (net.minecraft.entity.Entity entity : nmsEntities) {
apiEntities.add((Entity) entity);
}
return ImmutableList.copyOf(apiEntities);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since Minecraft's Entity implements the interface you can directly do ImmutableList.copyOf on the nmsEntities for some performance boosts

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.

^

}

}