use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.
the class ServerWorldMixin method updateBalloons.
@SuppressWarnings("deprecation")
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;inChunk:Z", ordinal = 1, shift = At.Shift.AFTER), method = "tickNonPassenger")
private void updateBalloons(Entity entity, CallbackInfo info) {
BalloonHolder balloonHolder = (BalloonHolder) entity;
ServerChunkProvider chunkProvider = ((ServerWorld) (Object) this).getChunkSource();
for (BolloomBalloonEntity balloon : balloonHolder.getBalloons()) {
if (!balloon.removed && balloon.getAttachedEntity() == entity) {
if (chunkProvider.isEntityTickingChunk(balloon)) {
balloon.setPosAndOldPos(balloon.getX(), balloon.getY(), balloon.getZ());
balloon.yRotO = balloon.yRot;
balloon.xRotO = balloon.xRot;
if (balloon.inChunk) {
balloon.tickCount++;
balloon.updateAttachedPosition();
}
((ServerWorld) (Object) this).updateChunkPos(balloon);
}
} else {
balloon.detachFromEntity();
}
}
}
use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.
the class BolloomBalloonItem method attachToEntity.
public static void attachToEntity(BalloonColor color, Entity target) {
World world = target.level;
BolloomBalloonEntity balloon = EEEntities.BOLLOOM_BALLOON.get().create(world);
if (balloon != null) {
balloon.setColor(color);
balloon.attachToEntity(target);
balloon.updateAttachedPosition();
balloon.setUntied(true);
world.addFreshEntity(balloon);
}
}
use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.
the class PlayerListMixin method spawnBalloons.
@Inject(at = @At("RETURN"), method = "placeNewPlayer")
private void spawnBalloons(NetworkManager netManager, ServerPlayerEntity player, CallbackInfo info) {
ServerWorld serverWorld = (ServerWorld) player.level;
CompoundNBT compound = this.server.getWorldData().getLoadedPlayerTag();
if (!(compound != null && player.getName().getString().equals(this.server.getSingleplayerName()))) {
try {
File playerDataFile = new File(this.playerIo.getPlayerDataFolder(), player.getStringUUID() + ".dat");
if (playerDataFile.exists() && playerDataFile.isFile()) {
compound = CompressedStreamTools.readCompressed(playerDataFile);
}
} catch (Exception exception) {
EndergeticExpansion.LOGGER.warn("Failed to load player data for {}", player.getName().getString());
}
}
if (compound != null && compound.contains("Balloons", 9)) {
ListNBT balloonsTag = compound.getList("Balloons", 10);
if (!balloonsTag.isEmpty()) {
for (int i = 0; i < balloonsTag.size(); i++) {
Entity entity = EntityType.loadEntityRecursive(balloonsTag.getCompound(i), serverWorld, (balloon -> !serverWorld.addWithUUID(balloon) ? null : balloon));
if (entity instanceof BolloomBalloonEntity) {
((BolloomBalloonEntity) entity).attachToEntity(player);
EndergeticExpansion.CHANNEL.send(PacketDistributor.TRACKING_ENTITY.with(() -> entity), new S2CUpdateBalloonsMessage(player));
}
}
}
}
}
use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.
the class PlayerListMixin method removeBalloons.
@SuppressWarnings("deprecation")
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;save(Lnet/minecraft/entity/player/ServerPlayerEntity;)V", shift = At.Shift.AFTER), method = "remove")
private void removeBalloons(ServerPlayerEntity player, CallbackInfo info) {
List<BolloomBalloonEntity> balloons = ((BalloonHolder) player).getBalloons();
if (!balloons.isEmpty()) {
ServerWorld serverWorld = (ServerWorld) player.level;
for (BolloomBalloonEntity balloon : balloons) {
serverWorld.despawn(balloon);
balloon.removed = true;
}
serverWorld.getChunk(player.xChunk, player.zChunk).markUnsaved();
}
}
use of com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity in project endergetic by team-abnormals.
the class EntityEvents method onPlayerSwing.
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onPlayerSwing(InputEvent.ClickInputEvent event) {
if (event.isAttack()) {
ClientPlayerEntity player = ClientInfo.getClientPlayer();
if (player.xRot > -25.0F)
return;
Entity ridingEntity = player.getVehicle();
if (ridingEntity instanceof BoatEntity && BolloomBalloonItem.hasNoEntityTarget(player) && EntityUtil.rayTrace(player, BolloomBalloonItem.getPlayerReach(player), 1.0F).getType() == Type.MISS) {
List<BolloomBalloonEntity> balloons = ((BalloonHolder) ridingEntity).getBalloons();
if (!balloons.isEmpty()) {
Minecraft.getInstance().gameMode.attack(player, balloons.get(player.getRandom().nextInt(balloons.size())));
event.setSwingHand(true);
}
}
}
}
Aggregations