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()));
});
}
use of net.minecraft.server.MinecraftServer in project malmo by Microsoft.
the class DefaultWorldGeneratorImplementation method shouldCreateWorld.
@Override
public boolean shouldCreateWorld(MissionInit missionInit) {
if (this.dwparams != null && this.dwparams.isForceReset())
return true;
World world = null;
MinecraftServer server = MinecraftServer.getServer();
if (server.worldServers != null && server.worldServers.length != 0)
world = server.getEntityWorld();
if (Minecraft.getMinecraft().theWorld == null || world == null)
// Definitely need to create a world if there isn't one in existence!
return true;
String genOptions = world.getWorldInfo().getGeneratorOptions();
if (genOptions != null && !genOptions.isEmpty())
// Default world has no generator options.
return true;
return false;
}
use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.
the class DimensionManager method initDimension.
public static void initDimension(int dim) {
WorldServer overworld = getWorld(0);
if (overworld == null) {
throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!");
}
try {
DimensionManager.getProviderType(dim);
} catch (Exception e) {
System.err.println("Cannot Hotload Dim: " + e.getMessage());
// If a provider hasn't been registered then we can't hotload the dim
return;
}
MinecraftServer mcServer = overworld.getMinecraftServer();
ISaveHandler savehandler = overworld.getSaveHandler();
//WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo());
WorldServer world = (dim == 0 ? overworld : (WorldServer) (new WorldServerMulti(mcServer, savehandler, dim, overworld, mcServer.theProfiler).init()));
world.addEventListener(new ServerWorldEventHandler(mcServer, world));
MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
if (!mcServer.isSinglePlayer()) {
world.getWorldInfo().setGameType(mcServer.getGameType());
}
mcServer.setDifficultyForAllWorlds(mcServer.getDifficulty());
}
use of net.minecraft.server.MinecraftServer in project MinecraftForge by MinecraftForge.
the class FMLCommonHandler method handleServerStopped.
public void handleServerStopped() {
sidedDelegate.serverStopped();
MinecraftServer server = getMinecraftServerInstance();
Loader.instance().serverStopped();
// FORCE the internal server to stop: hello optifine workaround!
if (server != null)
ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, server, false, "field_71316" + "_v", "u", "serverStopped");
// allow any pending exit to continue, clear exitLatch
CountDownLatch latch = exitLatch;
if (latch != null) {
latch.countDown();
exitLatch = null;
}
}
Aggregations