use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.
the class EntityCargoRocket method onReachAtmosphere.
@Override
public void onReachAtmosphere() {
if (this.worldObj.isRemote) {
// stop the sounds on the client - but do not reset, the rocket may start again
this.stopRocketSound();
return;
}
GCLog.debug("[Serverside] Cargo rocket reached space, heading to " + this.destinationFrequency);
this.setTarget(true, this.destinationFrequency);
if (this.targetVec != null) {
GCLog.debug("Destination location = " + this.targetVec.toString());
if (this.targetDimension != GCCoreUtil.getDimensionID(this.worldObj)) {
GCLog.debug("Destination is in different dimension: " + this.targetDimension);
WorldProvider targetDim = WorldUtil.getProviderForDimensionServer(this.targetDimension);
if (targetDim != null && targetDim.worldObj instanceof WorldServer) {
GCLog.debug("Loaded destination dimension " + this.targetDimension);
this.setPosition(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5F);
Entity e = WorldUtil.transferEntityToDimension(this, this.targetDimension, (WorldServer) targetDim.worldObj, false, null);
if (e instanceof EntityCargoRocket) {
GCLog.debug("Cargo rocket arrived at destination dimension, going into landing mode.");
e.setPosition(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5F);
((EntityCargoRocket) e).setLaunchPhase(EnumLaunchPhase.LANDING);
// No setDead() following successful transferEntityToDimension() - see javadoc on that
} else {
GCLog.info("Error: failed to recreate the cargo rocket in landing mode on target planet.");
e.setDead();
this.setDead();
}
return;
}
GCLog.info("Error: the server failed to load the dimension the cargo rocket is supposed to land in. Destroying rocket!");
this.setDead();
return;
} else {
GCLog.debug("Cargo rocket going into landing mode in same destination.");
this.setPosition(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5F);
this.setLaunchPhase(EnumLaunchPhase.LANDING);
return;
}
} else {
GCLog.info("Error: the cargo rocket failed to find a valid landing spot when it reached space.");
this.setDead();
}
}
use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.
the class EntityTieredRocket method onReachAtmosphere.
@Override
public void onReachAtmosphere() {
// Launch controlled
if (this.destinationFrequency != -1) {
if (this.worldObj.isRemote) {
// stop the sounds on the client - but do not reset, the rocket may start again
this.stopRocketSound();
return;
}
this.setTarget(true, this.destinationFrequency);
if (this.targetVec != null) {
if (this.targetDimension != this.worldObj.provider.getDimensionId()) {
WorldProvider targetDim = WorldUtil.getProviderForDimensionServer(this.targetDimension);
if (targetDim != null && targetDim.worldObj instanceof WorldServer) {
boolean dimensionAllowed = this.targetDimension == ConfigManagerCore.idDimensionOverworld;
if (targetDim instanceof IGalacticraftWorldProvider) {
if (((IGalacticraftWorldProvider) targetDim).canSpaceshipTierPass(this.getRocketTier()))
dimensionAllowed = true;
else
dimensionAllowed = false;
} else // No rocket flight to non-Galacticraft dimensions other than the Overworld allowed unless config
if ((this.targetDimension > 1 || this.targetDimension < -1) && marsConfigAllDimsAllowed != null) {
try {
if (marsConfigAllDimsAllowed.getBoolean(null)) {
dimensionAllowed = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (dimensionAllowed) {
if (this.riddenByEntity != null) {
WorldUtil.transferEntityToDimension(this.riddenByEntity, this.targetDimension, (WorldServer) targetDim.worldObj, false, this);
} else {
Entity e = WorldUtil.transferEntityToDimension(this, this.targetDimension, (WorldServer) targetDim.worldObj, false, null);
if (e instanceof EntityAutoRocket) {
e.setPosition(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5f);
((EntityAutoRocket) e).setLaunchPhase(EnumLaunchPhase.LANDING);
((EntityAutoRocket) e).setWaitForPlayer(false);
} else {
GCLog.info("Error: failed to recreate the unmanned rocket in landing mode on target planet.");
e.setDead();
this.setDead();
}
}
return;
}
}
// No destination world found - in this situation continue into regular take-off (as if Not launch controlled)
} else {
// Same dimension controlled rocket flight
this.setPosition(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5F);
// Stop any lateral motion, otherwise it will update to an incorrect x,z position first tick after spawning above target
this.motionX = this.motionZ = 0.0D;
// Small upward motion initially, to keep clear of own flame trail from launch
this.motionY = 0.1D;
if (this.riddenByEntity != null) {
WorldUtil.forceMoveEntityToPos(this.riddenByEntity, (WorldServer) this.worldObj, new Vector3(this.targetVec.getX() + 0.5F, this.targetVec.getY() + 800, this.targetVec.getZ() + 0.5F), false);
this.setWaitForPlayer(true);
GCLog.debug("Rocket repositioned, waiting for player");
}
this.setLaunchPhase(EnumLaunchPhase.LANDING);
// Do not destroy the rocket, we still need it!
return;
}
} else {
// Launch controlled launch but no valid target frequency = rocket loss [INVESTIGATE]
GCLog.info("Error: the launch controlled rocket failed to find a valid landing spot when it reached space.");
this.fuelTank.drain(Integer.MAX_VALUE, true);
this.posY = Math.max(255, (this.worldObj.provider instanceof IExitHeight ? ((IExitHeight) this.worldObj.provider).getYCoordinateToTeleport() : 1200) - 200);
return;
}
}
// Not launch controlled
if (!this.worldObj.isRemote) {
if (this.riddenByEntity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) this.riddenByEntity;
this.onTeleport(player);
GCPlayerStats stats = GCPlayerStats.get(player);
WorldUtil.toCelestialSelection(player, stats, this.getRocketTier());
}
// Destroy any rocket which reached the top of the atmosphere and is not controlled by a Launch Controller
this.setDead();
}
// Client side, non-launch controlled, do nothing - no reason why it can't continue flying until the GUICelestialSelection activates
}
use of net.minecraft.world.WorldProvider in project Galacticraft by micdoodle8.
the class TileEntityTelemetry method frequencyModulePlayer.
/**
* Call this when a player wears a frequency module to check
* whether it has been linked with a Telemetry Unit.
*
* @param held The frequency module
* @param player
*/
public static void frequencyModulePlayer(ItemStack held, EntityPlayerMP player, boolean remove) {
if (held == null) {
return;
}
NBTTagCompound fmData = held.getTagCompound();
if (fmData != null && fmData.hasKey("teDim")) {
int dim = fmData.getInteger("teDim");
int x = fmData.getInteger("teCoordX");
int y = fmData.getInteger("teCoordY");
int z = fmData.getInteger("teCoordZ");
WorldProvider wp = WorldUtil.getProviderForDimensionServer(dim);
// TODO
if (wp == null || wp.worldObj == null) {
GCLog.debug("Frequency module worn: world provider is null. This is a bug. " + dim);
} else {
TileEntity te = wp.worldObj.getTileEntity(new BlockPos(x, y, z));
if (te instanceof TileEntityTelemetry) {
if (remove) {
if (((TileEntityTelemetry) te).linkedEntity == player)
((TileEntityTelemetry) te).removeTrackedEntity();
} else {
((TileEntityTelemetry) te).addTrackedEntity(player.getUniqueID());
}
}
}
}
}
use of net.minecraft.world.WorldProvider in project SpongeForge by SpongePowered.
the class MixinWorldManager method getWorldFolder.
/**
* @author blood - August 10th, 2016
* @reason Constructs a WorldProvider instance in order to locate the save folder name to use.
*
* @return The path if available
*/
@Overwrite
public static Path getWorldFolder(DimensionType dimensionType, int dimensionId) {
Path path = dimensionPathByDimensionId.get(dimensionId);
if (path != null) {
return path;
}
if (dimensionType == null) {
return null;
}
try {
WorldProvider provider = dimensionType.createDimension();
provider.setDimension(dimensionId);
String worldFolder = provider.getSaveFolder();
path = SpongeImpl.getGame().getSavesDirectory().resolve(SpongeImpl.getServer().getFolderName()).resolve(worldFolder);
WorldManager.registerDimensionPath(dimensionId, path);
} catch (Throwable t) {
t.printStackTrace();
}
return path;
}
use of net.minecraft.world.WorldProvider in project GregTech by GregTechCE.
the class WorldConfigUtils method createWorldPredicate.
public static Predicate<WorldProvider> createWorldPredicate(JsonElement element) {
Preconditions.checkArgument(element.isJsonArray(), "World filter should be array!");
JsonArray predicateArray = element.getAsJsonArray();
ArrayList<Predicate<WorldProvider>> allPredicates = new ArrayList<>();
for (JsonElement worldPredicate : predicateArray) {
String stringValue = worldPredicate.getAsString();
if (stringValue.equals("is_surface_world")) {
allPredicates.add(WorldProvider::isSurfaceWorld);
continue;
} else if (stringValue.equals("is_nether")) {
allPredicates.add(wp -> wp.isNether() || wp.getDimensionType() == DimensionType.NETHER);
continue;
}
Function<WorldProvider, String> stringSupplier = null;
if (stringValue.startsWith("dimension_id:")) {
String filterValue = stringValue.substring(13);
if (filterValue.indexOf(':') == -1) {
int dimensionId = Integer.parseInt(filterValue);
allPredicates.add(provider -> provider.getDimension() == dimensionId);
} else {
int indexOf = filterValue.indexOf(':');
int indexOfExclusive = indexOf + 1;
int minDimensionId = indexOf == 0 ? -Integer.MAX_VALUE : Integer.parseInt(filterValue.substring(0, indexOf));
int maxDimensionId = indexOfExclusive == filterValue.length() ? Integer.MAX_VALUE : Integer.parseInt(filterValue.substring(indexOfExclusive));
allPredicates.add(provider -> provider.getDimension() >= minDimensionId && provider.getDimension() <= maxDimensionId);
}
} else if (stringValue.startsWith("name:")) {
stringSupplier = provider -> provider.getDimensionType().getName();
stringValue = stringValue.substring(5);
} else if (stringValue.startsWith("provider_class:")) {
stringSupplier = provider -> provider.getClass().getSimpleName();
stringValue = stringValue.substring(15);
} else
throw new IllegalArgumentException("Unknown world predicate: " + stringValue);
if (stringSupplier != null) {
if (stringValue.startsWith("*")) {
Pattern pattern = Pattern.compile(stringValue.substring(1));
Function<WorldProvider, String> finalStringSupplier = stringSupplier;
allPredicates.add(provider -> pattern.matcher(finalStringSupplier.apply(provider)).matches());
} else {
String finalStringValue = stringValue;
Function<WorldProvider, String> finalStringSupplier1 = stringSupplier;
allPredicates.add(provider -> finalStringValue.equalsIgnoreCase(finalStringSupplier1.apply(provider)));
}
}
}
return provider -> allPredicates.stream().anyMatch(p -> p.test(provider));
}
Aggregations