use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.
the class PlaneItem method use.
@Override
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
HitResult hitResult = getPlayerPOVHitResult(worldIn, playerIn, ClipContext.Fluid.ANY);
if (hitResult.getType() == HitResult.Type.MISS) {
return InteractionResultHolder.pass(itemstack);
} else {
Vec3 vec3d = playerIn.getViewVector(1.0F);
List<Entity> list = worldIn.getEntities(playerIn, playerIn.getBoundingBox().expandTowards(vec3d.scale(5.0D)).inflate(1.0D), ENTITY_PREDICATE);
if (!list.isEmpty()) {
Vec3 vec3d1 = playerIn.getEyePosition(1.0F);
for (Entity entity : list) {
AABB aabb = entity.getBoundingBox().inflate(entity.getPickRadius());
if (aabb.contains(vec3d1)) {
return InteractionResultHolder.pass(itemstack);
}
}
}
if (hitResult.getType() == HitResult.Type.BLOCK) {
PlaneEntity planeEntity = planeEntityType.get().create(worldIn);
planeEntity.setPos(hitResult.getLocation().x(), hitResult.getLocation().y(), hitResult.getLocation().z());
planeEntity.setYRot(playerIn.getYRot());
planeEntity.yRotO = playerIn.yRotO;
planeEntity.setCustomName(itemstack.getHoverName());
CompoundTag entityTag = itemstack.getTagElement("EntityTag");
if (entityTag != null) {
planeEntity.readAdditionalSaveData(entityTag);
}
if (!worldIn.noCollision(planeEntity, planeEntity.getBoundingBox().inflate(-0.1D))) {
return InteractionResultHolder.fail(itemstack);
} else {
if (!worldIn.isClientSide) {
worldIn.addFreshEntity(planeEntity);
if (!playerIn.getAbilities().instabuild) {
itemstack.shrink(1);
}
}
playerIn.awardStat(Stats.ITEM_USED.get(this));
return InteractionResultHolder.success(itemstack);
}
} else {
return InteractionResultHolder.pass(itemstack);
}
}
}
use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.
the class UpdateUpgradePacket method handle.
public void handle(Supplier<NetworkEvent.Context> ctxSup) {
NetworkEvent.Context ctx = ctxSup.get();
ctx.enqueueWork(() -> {
ClientLevel clientWorld = Minecraft.getInstance().level;
((PlaneEntity) clientWorld.getEntity(planeEntityID)).readUpdateUpgradePacket(upgradeID, packetBuffer, newUpgrade);
});
ctx.setPacketHandled(true);
}
use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.
the class CommonEventHandler method interact.
@SubscribeEvent
public static void interact(PlayerInteractEvent.RightClickItem event) {
Player player = event.getPlayer();
Entity entity = player.getRootVehicle();
if (entity instanceof PlaneEntity) {
ItemStack itemStack = player.getItemInHand(event.getHand());
if (!itemStack.isEmpty()) {
if (itemStack.getItem() == Items.TNT && entity instanceof LargePlaneEntity && ((LargePlaneEntity) entity).tryToAddTNT(player, itemStack)) {
return;
}
PlaneEntity planeEntity = (PlaneEntity) entity;
for (Upgrade upgrade : planeEntity.upgrades.values()) {
upgrade.onItemRightClick(event);
}
}
}
}
use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.
the class RemoveUpgradesScreen method init.
@Override
protected void init() {
super.init();
Entity entity = minecraft.level.getEntity(menu.planeID);
if (entity instanceof PlaneEntity) {
buttonsList = new UpgradeButtonsList(minecraft, 120, height, 32, height - 61, 20, (PlaneEntity) entity);
addRenderableWidget(buttonsList);
} else {
onClose();
}
}
use of xyz.przemyk.simpleplanes.entities.PlaneEntity in project simple-planes by przemykomo.
the class SUpgradeRemovedPacket method handle.
public void handle(Supplier<NetworkEvent.Context> ctxSup) {
NetworkEvent.Context ctx = ctxSup.get();
ctx.enqueueWork(() -> {
ClientLevel clientWorld = Minecraft.getInstance().level;
((PlaneEntity) clientWorld.getEntity(planeEntityID)).removeUpgrade(upgradeID);
});
ctx.setPacketHandled(true);
}
Aggregations