-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
10 changed files
with
90 additions
and
6 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
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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/eu/pb4/graves/mixin/ExperienceOrbEntityAccessor.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package eu.pb4.graves.mixin; | ||
|
||
import net.minecraft.entity.ExperienceOrbEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ExperienceOrbEntity.class) | ||
public interface ExperienceOrbEntityAccessor { | ||
@Accessor | ||
void setAmount(int amount); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package eu.pb4.graves.registry; | ||
|
||
import eu.pb4.graves.mixin.ExperienceOrbEntityAccessor; | ||
import eu.pb4.polymer.api.entity.PolymerEntity; | ||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityDimensions; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.ExperienceOrbEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public class SafeXPEntity extends ExperienceOrbEntity implements PolymerEntity { | ||
public static EntityType<Entity> TYPE = FabricEntityTypeBuilder.create().entityFactory(SafeXPEntity::new).fireImmune().disableSummon().dimensions(EntityDimensions.fixed(0.5F, 0.5F)).trackRangeChunks(6).trackedUpdateRate(20).build(); | ||
public SafeXPEntity(World world, double x, double y, double z, int amount) { | ||
this(TYPE, world); | ||
this.setPosition(x, y, z); | ||
this.setYaw((float)(this.random.nextDouble() * 360.0D)); | ||
this.setVelocity((this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D, this.random.nextDouble() * 0.2D * 2.0D, (this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D); | ||
((ExperienceOrbEntityAccessor) this).setAmount(amount); | ||
} | ||
|
||
public SafeXPEntity(EntityType<Entity> entityType, World world) { | ||
super((EntityType<? extends ExperienceOrbEntity>) (Object) entityType, world); | ||
} | ||
|
||
public static void spawn(ServerWorld world, Vec3d pos, int amount) { | ||
world.spawnEntity(new SafeXPEntity(world, pos.getX(), pos.getY(), pos.getZ(), amount)); | ||
} | ||
|
||
@Override | ||
public void onPlayerCollision(PlayerEntity player) { | ||
if (!this.world.isClient) { | ||
if (player.experiencePickUpDelay == 0) { | ||
player.experiencePickUpDelay = 2; | ||
player.sendPickup(this, 1); | ||
player.addExperience(this.getExperienceAmount()); | ||
this.discard(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public EntityType<?> getPolymerEntityType() { | ||
return EntityType.EXPERIENCE_BOTTLE; | ||
} | ||
} |
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