Skip to content

Commit

Permalink
Feat: add ItemEntity wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldenfield192 committed Oct 24, 2024
1 parent 64b202d commit e5e5a8b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
46 changes: 46 additions & 0 deletions src/main/java/cam72cam/mod/entity/ItemEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cam72cam.mod.entity;

import cam72cam.mod.item.ItemStack;

import java.util.UUID;

/** Wrapper around ItemEntity */
public class ItemEntity extends Entity{
public net.minecraft.entity.item.ItemEntity internal;

public ItemEntity(net.minecraft.entity.item.ItemEntity entity) {
super(entity);
this.internal = entity;
}

public ItemStack getContent(){
return new ItemStack(internal.getItem());
}

public UUID getOwner(){
return internal.getOwnerId();
}

public UUID getThrower(){
return internal.getThrowerId();
}
public void setDefaultPickupDelay() {
internal.setDefaultPickupDelay();
}

public void setNoPickupDelay() {
internal.setNoPickupDelay();
}

public void setInfinitePickupDelay() {
internal.setInfinitePickupDelay();
}

public void setPickupDelay(int ticks) {
internal.setPickupDelay(ticks);
}

public void setNoDespawn(){
internal.setNoDespawn();
}
}
29 changes: 19 additions & 10 deletions src/main/java/cam72cam/mod/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Direction;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.LightType;
Expand Down Expand Up @@ -205,6 +204,8 @@ void onEntityAdded(net.minecraft.entity.Entity entityIn) {
entity = new Player((PlayerEntity) entityIn);
} else if (entityIn instanceof LivingEntity) {
entity = new Living((LivingEntity) entityIn);
} else if (entityIn instanceof ItemEntity) {
entity = new cam72cam.mod.entity.ItemEntity((ItemEntity) entityIn);
} else {
entity = new Entity(entityIn);
}
Expand Down Expand Up @@ -467,21 +468,22 @@ public float getTemperature(Vec3i pos) {
return (13.6484805403f * mctemp) + 7.0879687222f;
}

/** Drop a stack on the ground at pos */
public void dropItem(ItemStack stack, Vec3i pos) {
dropItem(stack, new Vec3d(pos), Vec3d.ZERO);
/** Drop a stack on the ground at pos and returns its entity reference */
public cam72cam.mod.entity.ItemEntity dropItem(ItemStack stack, Vec3i pos) {
return dropItem(stack, new Vec3d(pos), Vec3d.ZERO);
}

/** Drop a stack on the ground at pos */
public void dropItem(ItemStack stack, Vec3d pos) {
dropItem(stack, pos, Vec3d.ZERO);
/** Drop a stack on the ground at pos and returns its entity reference */
public cam72cam.mod.entity.ItemEntity dropItem(ItemStack stack, Vec3d pos) {
return dropItem(stack, pos, Vec3d.ZERO);
}

/** Drop a stack on the ground at pos with velocity */
public void dropItem(ItemStack stack, Vec3d pos, Vec3d velocity) {
/** Drop a stack on the ground at pos with velocity and returns its entity reference */
public cam72cam.mod.entity.ItemEntity dropItem(ItemStack stack, Vec3d pos, Vec3d velocity) {
ItemEntity entity = new ItemEntity(internal, pos.x, pos.y, pos.z, stack.internal);
entity.setVelocity(velocity.x, velocity.y, velocity.z);
internal.addEntity(entity);
return getEntity(entity.getEntityId(), cam72cam.mod.entity.ItemEntity.class);
}

/** Check if the block is currently in a loaded chunk */
Expand Down Expand Up @@ -654,6 +656,13 @@ public List<ItemStack> getDroppedItems(IBoundingBox bb) {
return items.stream().map((ItemEntity::getItem)).map(ItemStack::new).collect(Collectors.toList());
}

/** Get dropped items within the given area in entity form*/
public List<cam72cam.mod.entity.ItemEntity> getItemEntitiesWithinBB(IBoundingBox bb) {
return internal.getEntitiesWithinAABB(ItemEntity.class, BoundingBox.from(bb)).stream()
.map(itemEntity -> this.getEntity(itemEntity.getEntityId(), cam72cam.mod.entity.ItemEntity.class))
.collect(Collectors.toList());
}

/** Get a BlockInfo that can be used to overwrite a block in the future. Does not currently include TE data */
public BlockInfo getBlock(Vec3i pos) {
return new BlockInfo(internal.getBlockState(pos.internal()));
Expand Down Expand Up @@ -719,4 +728,4 @@ public float getBlockLightLevel(Vec3i pos) {
public float getSkyLightLevel(Vec3i pos) {
return internal.getLightFor(LightType.SKY, pos.internal()) / 15f;
}
}
}

0 comments on commit e5e5a8b

Please sign in to comment.