use of net.minecraft.server.MinecraftServer in project Galacticraft by micdoodle8.
the class VenusTickHandlerServer method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
// Prevent issues when clients switch to LAN servers
if (server == null) {
return;
}
if (event.phase == Phase.END) {
for (SolarModuleNetwork network : new ArrayList<>(solarModuleNetworks)) {
if (!network.getTransmitters().isEmpty()) {
// network.tickEnd();
} else {
solarModuleNetworks.remove(network);
}
}
int maxPasses = 10;
while (!solarTransmitterUpdates.isEmpty()) {
LinkedList<TileEntitySolarTransmitter> pass = new LinkedList<>();
pass.addAll(solarTransmitterUpdates);
solarTransmitterUpdates.clear();
for (TileEntitySolarTransmitter newTile : pass) {
if (!newTile.isInvalid()) {
newTile.refresh();
}
}
if (--maxPasses <= 0) {
break;
}
}
}
}
use of net.minecraft.server.MinecraftServer in project Galacticraft by micdoodle8.
the class EntityTieredRocket method onUpdate.
@Override
public void onUpdate() {
if (this.getWaitForPlayer()) {
if (!this.getPassengers().isEmpty()) {
Entity passenger = this.getPassengers().get(0);
if (this.ticks >= 40) {
if (!this.world.isRemote) {
this.removePassengers();
passenger.startRiding(this, true);
GCLog.debug("Remounting player in rocket.");
}
this.setWaitForPlayer(false);
this.motionY = -0.5D;
} else {
this.motionX = this.motionY = this.motionZ = 0.0D;
passenger.motionX = passenger.motionY = passenger.motionZ = 0;
}
} else {
this.motionX = this.motionY = this.motionZ = 0.0D;
}
}
super.onUpdate();
if (!this.world.isRemote) {
if (this.launchCooldown > 0) {
this.launchCooldown--;
}
if (this.preGenIterator != null) {
if (this.preGenIterator.hasNext()) {
MinecraftServer mcserver;
if (this.world instanceof WorldServer) {
mcserver = ((WorldServer) this.world).getMinecraftServer();
BlockVec3 coords = this.preGenIterator.next();
World w = mcserver.getWorld(coords.y);
if (w != null) {
w.getChunkFromChunkCoords(coords.x, coords.z);
// Pregen a second chunk if still on launchpad (low strain on server)
if (this.launchPhase < EnumLaunchPhase.LAUNCHED.ordinal() && this.preGenIterator.hasNext()) {
coords = this.preGenIterator.next();
w = mcserver.getWorld(coords.y);
w.getChunkFromChunkCoords(coords.x, coords.z);
}
}
}
} else {
this.preGenIterator = null;
EntityTieredRocket.preGenInProgress = false;
}
}
}
if (this.rumble > 0) {
this.rumble--;
} else if (this.rumble < 0) {
this.rumble++;
}
final double rumbleAmount = this.rumble / (double) (37 - 5 * Math.max(this.getRocketTier(), 5));
for (Entity passenger : this.getPassengers()) {
passenger.posX += rumbleAmount;
passenger.posZ += rumbleAmount;
}
if (this.launchPhase >= EnumLaunchPhase.IGNITED.ordinal()) {
this.performHurtAnimation();
this.rumble = (float) this.rand.nextInt(3) - 3;
}
if (!this.world.isRemote) {
this.lastLastMotionY = this.lastMotionY;
this.lastMotionY = this.motionY;
}
}
use of net.minecraft.server.MinecraftServer in project Galacticraft by micdoodle8.
the class WorldUtil method transferEntityToDimension.
/**
* It is not necessary to use entity.setDead() following calling this method.
* If the entity left the old world it was in, it will now automatically be removed from that old world before the next update tick.
* (See WorldUtil.removeEntityFromWorld())
*/
public static Entity transferEntityToDimension(Entity entity, int dimensionID, WorldServer world, boolean transferInv, EntityAutoRocket ridingRocket) {
if (!world.isRemote) {
// GalacticraftCore.packetPipeline.sendToAll(new PacketSimple(EnumSimplePacket.C_UPDATE_PLANETS_LIST, WorldUtil.getPlanetList()));
MinecraftServer mcServer = world.getMinecraftServer();
if (mcServer != null) {
final WorldServer var6 = mcServer.getWorld(dimensionID);
if (var6 == null) {
System.err.println("Cannot Transfer Entity to Dimension: Could not get World for Dimension " + dimensionID);
return null;
}
final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(var6.provider.getClass());
if (type != null) {
return WorldUtil.teleportEntity(var6, entity, dimensionID, type, transferInv, ridingRocket);
}
}
}
return null;
}
use of net.minecraft.server.MinecraftServer in project Galacticraft by micdoodle8.
the class AsteroidsTickHandlerServer method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
// Prevent issues when clients switch to LAN servers
if (server == null) {
return;
}
if (event.phase == TickEvent.Phase.START) {
TileEntityMinerBase.checkNewMinerBases();
if (AsteroidsTickHandlerServer.spaceRaceData == null) {
World world = server.getWorld(0);
AsteroidsTickHandlerServer.spaceRaceData = (ShortRangeTelepadHandler) world.getMapStorage().getOrLoadData(ShortRangeTelepadHandler.class, ShortRangeTelepadHandler.saveDataID);
if (AsteroidsTickHandlerServer.spaceRaceData == null) {
AsteroidsTickHandlerServer.spaceRaceData = new ShortRangeTelepadHandler(ShortRangeTelepadHandler.saveDataID);
world.getMapStorage().setData(ShortRangeTelepadHandler.saveDataID, AsteroidsTickHandlerServer.spaceRaceData);
}
}
int index = -1;
for (EntityAstroMiner miner : activeMiners) {
index++;
if (miner.isDead) {
// minerIt.remove(); Don't remove it, we want the index number to be static for the others
continue;
}
if (miner.playerMP != null) {
GCPlayerStats stats = GCPlayerStats.get(miner.playerMP);
if (stats != null) {
List<BlockVec3> list = stats.getActiveAstroMinerChunks();
boolean inListAlready = false;
Iterator<BlockVec3> it = list.iterator();
while (it.hasNext()) {
BlockVec3 data = it.next();
if (// SideDoneBits won't be saved to NBT, but during an active server session we can use it as a cross-reference to the index here - it's a 4th data int hidden inside a BlockVec3
data.sideDoneBits == index) {
if (miner.isDead) {
// Player stats should not save position of dead AstroMiner entity (probably broken by player deliberately breaking it)
it.remove();
} else {
data.x = miner.chunkCoordX;
data.z = miner.chunkCoordZ;
}
inListAlready = true;
break;
}
}
if (!inListAlready) {
BlockVec3 data = new BlockVec3(miner.chunkCoordX, miner.dimension, miner.chunkCoordZ);
data.sideDoneBits = index;
list.add(data);
}
}
}
}
}
}
use of net.minecraft.server.MinecraftServer in project Wizardry by TeamWizardry.
the class BlockFluidMana method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
Entity entityIn = event.getEntity();
BlockPos pos = entityIn.getPosition();
World world = entityIn.world;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
// Fizz all entities in the pool
if (world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> true, entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));
// Nullify gravity of player
if (!world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> {
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
if (RandUtil.nextInt(50) == 0)
entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
});
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> entityIn.motionY += 0.003);
// Subtract player food
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityPlayer, entity -> {
if (!world.isRemote) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
if (advancement == null)
return;
AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
for (String s : progress.getRemaningCriteria()) {
((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
}
}
if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
});
// Explode explodable items
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IPotionEffectExplodable, entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
}
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> {
List<Map.Entry<Ingredient, FluidRecipeBuilder.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
});
}
Aggregations