Help With Dimensions not working after code rebuild

Started by Xaero1317 on Sat, 08/15/2020 - 18:30

Topic category: Help with MCreator software

Last seen on 02:25, 25. Apr 2021
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Help With Dimensions not working after code rebuild
Sat, 08/15/2020 - 18:30

As I was making a mod, Gradle asked to Remove all files and regenerate code. After I did this, all of my Dimensions, and any new ones I made, had errors. I deleted them and all of my blocks and items had errors. when I added a new Dimension, the block and item errors went away, but the Dimension error came back! 

Here is the code for my dimension. If you can help me, Thank you!


package net.mcreator.oregalore.world.dimension;

import org.jline.terminal.Size;

import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.world.RegisterDimensionsEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.common.util.ITeleporter;
import net.minecraftforge.common.ModDimension;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.server.TicketType;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.gen.layer.traits.IC0Transformer;
import net.minecraft.world.gen.layer.ZoomLayer;
import net.minecraft.world.gen.layer.Layer;
import net.minecraft.world.gen.layer.IslandLayer;
import net.minecraft.world.gen.area.LazyArea;
import net.minecraft.world.gen.area.IAreaFactory;
import net.minecraft.world.gen.LazyAreaLayerContext;
import net.minecraft.world.gen.INoiseRandom;
import net.minecraft.world.gen.IExtendedNoiseRandom;
import net.minecraft.world.gen.EndGenerationSettings;
import net.minecraft.world.gen.EndChunkGenerator;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.world.IWorld;
import net.minecraft.village.PointOfInterestType;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Direction;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.NetherPortalBlock;
import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Block;

import net.mcreator.oregalore.item.AfterTheEndItem;
import net.mcreator.oregalore.block.OilBlock;
import net.mcreator.oregalore.OreGaloreModElements;

import javax.annotation.Nullable;

import java.util.function.LongFunction;
import java.util.function.Function;
import java.util.function.BiFunction;
import java.util.Set;
import java.util.Random;
import java.util.HashSet;
import java.util.Arrays;

import java.lang.reflect.Method;

import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;

@OreGaloreModElements.ModElement.Tag
public class AfterTheEndDimension extends OreGaloreModElements.ModElement {
	@ObjectHolder("ore_galore:after_the_end")
	public static final ModDimension dimension = null;
	@ObjectHolder("ore_galore:after_the_end_portal")
	public static final CustomPortalBlock portal = null;
	public static DimensionType type = null;
	private static Biome[] dimensionBiomes;
	public AfterTheEndDimension(OreGaloreModElements instance) {
		super(instance, 537);
		MinecraftForge.EVENT_BUS.register(this);
		FMLJavaModLoadingContext.get().getModEventBus().register(this);
	}

	@SubscribeEvent
	public void registerDimension(RegistryEvent.Register<ModDimension> event) {
		event.getRegistry().register(new CustomModDimension().setRegistryName("after_the_end"));
	}

	@SubscribeEvent
	public void onRegisterDimensionsEvent(RegisterDimensionsEvent event) {
		if (DimensionType.byName(new ResourceLocation("ore_galore:after_the_end")) == null) {
			DimensionManager.registerDimension(new ResourceLocation("ore_galore:after_the_end"), dimension, null, true);
		}
		type = DimensionType.byName(new ResourceLocation("ore_galore:after_the_end"));
	}

	@Override
	public void init(FMLCommonSetupEvent event) {
		dimensionBiomes = new Biome[]{ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:lost_lands")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:obsidian_plains")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:lava_plains")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:hot_potatoes")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:not_the_end_biome")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:lava_avenue")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:acid_plains")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:freezing_ocean")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:flat_lands")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:spikey_terrain")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("ore_galore:nether_blue_lands")),
				ForgeRegistries.BIOMES.getValue(new ResourceLocation("small_end_islands")),};
	}

	@Override
	public void initElements() {
		elements.blocks.add(() -> new CustomPortalBlock());
		elements.items.add(() -> new AfterTheEndItem().setRegistryName("after_the_end"));
	}

	@Override
	@OnlyIn(Dist.CLIENT)
	public void clientLoad(FMLClientSetupEvent event) {
		RenderTypeLookup.setRenderLayer(portal, RenderType.getTranslucent());
	}
	public static class CustomPortalBlock extends NetherPortalBlock {
		public CustomPortalBlock() {
			super(Block.Properties.create(Material.PORTAL).doesNotBlockMovement().tickRandomly().hardnessAndResistance(-1.0F).sound(SoundType.GLASS)
					.lightValue(15).noDrops());
			setRegistryName("after_the_end_portal");
		}

		@Override
		public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
		}

		public void portalSpawn(World world, BlockPos pos) {
			CustomPortalBlock.Size portalsize = this.isValid(world, pos);
			if (portalsize != null)
				portalsize.placePortalBlocks();
		}

		/* failed to load code for net.minecraft.block.NetherPortalBlock */
		/* failed to load code for net.minecraft.block.NetherPortalBlock */
		@Override /* failed to load code for net.minecraft.block.NetherPortalBlock */
		@OnlyIn(Dist.CLIENT)
		@Override
		public void animateTick(BlockState state, World world, BlockPos pos, Random random) {
			for (int i = 0; i < 4; i++) {
				double px = pos.getX() + random.nextFloat();
				double py = pos.getY() + random.nextFloat();
				double pz = pos.getZ() + random.nextFloat();
				double vx = (random.nextFloat() - 0.5) / 2f;
				double vy = (random.nextFloat() - 0.5) / 2f;
				double vz = (random.nextFloat() - 0.5) / 2f;
				int j = random.nextInt(4) - 1;
				if (world.getBlockState(pos.west()).getBlock() != this && world.getBlockState(pos.east()).getBlock() != this) {
					px = pos.getX() + 0.5 + 0.25 * j;
					vx = random.nextFloat() * 2 * j;
				} else {
					pz = pos.getZ() + 0.5 + 0.25 * j;
					vz = random.nextFloat() * 2 * j;
				}
				world.addParticle(ParticleTypes.HAPPY_VILLAGER, px, py, pz, vx, vy, vz);
			}
			if (random.nextInt(110) == 0)
				world.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
						(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(("block.portal.ambient"))),
						SoundCategory.BLOCKS, 0.5f, random.nextFloat() * 0.4F + 0.8F, false);
		}

		@Override
		public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
			if (!entity.isPassenger() && !entity.isBeingRidden() && entity.isNonBoss() && !entity.world.isRemote && true) {
				if (entity.timeUntilPortal > 0) {
					entity.timeUntilPortal = entity.getPortalCooldown();
				} else if (entity.dimension != type) {
					entity.timeUntilPortal = entity.getPortalCooldown();
					teleportToDimension(entity, pos, type);
				} else {
					entity.timeUntilPortal = entity.getPortalCooldown();
					teleportToDimension(entity, pos, DimensionType.OVERWORLD);
				}
			}
		}

		private void teleportToDimension(Entity entity, BlockPos pos, DimensionType destinationType) {
			entity.changeDimension(destinationType, getTeleporterForDimension(entity, pos, entity.getServer().getWorld(destinationType)));
		}

		private TeleporterDimensionMod getTeleporterForDimension(Entity entity, BlockPos pos, ServerWorld nextWorld) {
			BlockPattern.PatternHelper bph = AfterTheEndDimension.CustomPortalBlock.createPatternHelper(entity.world, pos);
			double d0 = bph.getForwards().getAxis() == Direction.Axis.X
					? (double) bph.getFrontTopLeft().getZ()
					: (double) bph.getFrontTopLeft().getX();
			double d1 = bph.getForwards().getAxis() == Direction.Axis.X ? entity.getPosZ() : entity.getPosX();
			d1 = Math.abs(MathHelper.pct(d1 - (double) (bph.getForwards().rotateY().getAxisDirection() == Direction.AxisDirection.NEGATIVE ? 1 : 0),
					d0, d0 - (double) bph.getWidth()));
			double d2 = MathHelper.pct(entity.getPosY() - 1, (double) bph.getFrontTopLeft().getY(),
					(double) (bph.getFrontTopLeft().getY() - bph.getHeight()));
			return new TeleporterDimensionMod(nextWorld, new Vec3d(d1, d2, 0), bph.getForwards());
		}
	public static class Size /* failed to load code for net.minecraft.block.NetherPortalBlock */
}
		private static PointOfInterestType poi = null;
		public static final TicketType<BlockPos> CUSTOM_PORTAL = TicketType.create("after_the_end_portal", Vec3i::compareTo, 300);
		@SubscribeEvent
		public void registerPointOfInterest(RegistryEvent.Register<PointOfInterestType> event) {
			try {
				Method method = ObfuscationReflectionHelper.findMethod(PointOfInterestType.class, "func_226359_a_", String.class, Set.class,
						int.class, int.class);
				method.setAccessible(true);
				poi = (PointOfInterestType) method.invoke(null, "after_the_end_portal",
						Sets.newHashSet(ImmutableSet.copyOf(portal.getStateContainer().getValidStates())), 0, 1);
				event.getRegistry().register(poi);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		public static class TeleporterDimensionMod implements ITeleporter {
			private Vec3d lastPortalVec;
			private Direction teleportDirection;
			protected final ServerWorld world;
			protected final Random random;
			public TeleporterDimensionMod(ServerWorld worldServer, Vec3d lastPortalVec, Direction teleportDirection) {
				this.world = worldServer;
				this.random = new Random(worldServer.getSeed());
				this.lastPortalVec = lastPortalVec;
				this.teleportDirection = teleportDirection;
			}

			/* failed to load code for net.minecraft.world.Teleporter */
			/* failed to load code for net.minecraft.world.Teleporter */
			/* failed to load code for net.minecraft.world.Teleporter */
			@Override
			public Entity placeEntity(Entity entity, ServerWorld serverworld, ServerWorld serverworld1, float yaw,
					Function<Boolean, Entity> repositionEntity) {
				double d0 = entity.getPosX();
				double d1 = entity.getPosY();
				double d2 = entity.getPosZ();
				if (entity instanceof ServerPlayerEntity) {
					entity.setLocationAndAngles(d0, d1, d2, yaw, entity.rotationPitch);
					if (!this.placeInPortal(entity, yaw)) {
						this.makePortal(entity);
						this.placeInPortal(entity, yaw);
					}
					entity.setWorld(serverworld1);
					serverworld1.addDuringPortalTeleport((ServerPlayerEntity) entity);
					((ServerPlayerEntity) entity).connection.setPlayerLocation(entity.getPosX(), entity.getPosY(), entity.getPosZ(), yaw,
							entity.rotationPitch);
					return entity;
				} else {
					Vec3d vec3d = entity.getMotion();
					BlockPos blockpos = new BlockPos(d0, d1, d2);
					BlockPattern.PortalInfo blockpattern$portalinfo = this.placeInExistingPortal(blockpos, vec3d, teleportDirection, lastPortalVec.x,
							lastPortalVec.y, entity instanceof PlayerEntity);
					if (blockpattern$portalinfo == null)
						return null;
					blockpos = new BlockPos(blockpattern$portalinfo.pos);
					vec3d = blockpattern$portalinfo.motion;
					float f = (float) blockpattern$portalinfo.rotation;
					Entity entityNew = entity.getType().create(serverworld1);
					if (entityNew != null) {
						entityNew.copyDataFromOld(entity);
						entityNew.moveToBlockPosAndAngles(blockpos, entityNew.rotationYaw + f, entityNew.rotationPitch);
						entityNew.setMotion(vec3d);
						serverworld1.addFromAnotherDimension(entityNew);
					}
					return entityNew;
				}
			}
		}

		public static class CustomModDimension extends ModDimension {
			@Override
			public BiFunction<World, DimensionType, ? extends Dimension> getFactory() {
				return CustomDimension::new;
			}
		}

	public static class CustomDimension extends Dimension {
		private BiomeProviderCustom biomeProviderCustom = null;
		public CustomDimension(World world, DimensionType type) {
			super(world, type, 0.5f);
			this.nether = false;
		}
		@Override @OnlyIn(Dist.CLIENT) public Vec3d getFogColor(float cangle, float ticks) {
			return new Vec3d(0.8,0,0);
		}
		@Override public ChunkGenerator<?> createChunkGenerator() {
			if(this.biomeProviderCustom == null) {
				this.biomeProviderCustom = new BiomeProviderCustom(this.world);
			}
			return new ChunkProviderModded(this.world, this.biomeProviderCustom);
		}
		@Override public boolean isSurfaceWorld() {
			return false;
		}
		@Override public boolean canRespawnHere() {
			return false;
		}
		@OnlyIn(Dist.CLIENT) @Override public boolean doesXZShowFog(int x, int z) {
			return true;
		}
		@Override public SleepResult canSleepAt(PlayerEntity player, BlockPos pos){
        	return SleepResult.DENY;
		}
		@Nullable public BlockPos findSpawn(ChunkPos chunkPos, boolean checkValid) {
   		   return null;
   		}
   		@Nullable public BlockPos findSpawn(int x, int z, boolean checkValid) {
   		   return null;
   		}
		@Override public boolean doesWaterVaporize() {
      		return false;
   		}
		@Override /* failed to load code for net.minecraft.world.dimension.OverworldDimension */
	}

		public static class ChunkProviderModded extends EndChunkGenerator {
			public ChunkProviderModded(IWorld world, BiomeProvider provider) {
				super(world, provider, new EndGenerationSettings() {
					public BlockState getDefaultBlock() {
						return Blocks.MOSSY_COBBLESTONE.getDefaultState();
					}

					public BlockState getDefaultFluid() {
						return OilBlock.block.getDefaultState();
					}
				});
				this.randomSeed.skip(3946);
			}
		}

		public static class BiomeLayerCustom implements IC0Transformer {
			@Override
			public int apply(INoiseRandom context, int value) {
				return Registry.BIOME.getId(dimensionBiomes[context.random(dimensionBiomes.length)]);
			}
		}

		public static class BiomeProviderCustom extends BiomeProvider {
			private Layer genBiomes;
			public BiomeProviderCustom(World world) {
				super(new HashSet<Biome>(Arrays.asList(dimensionBiomes)));
				this.genBiomes = getBiomeLayer(world.getSeed());
			}

			public Biome getNoiseBiome(int x, int y, int z) {
				return this.genBiomes.func_215738_a(x, z);
			}

			private Layer getBiomeLayer(long seed) {
				LongFunction<IExtendedNoiseRandom<LazyArea>> contextFactory = l -> new LazyAreaLayerContext(25, seed, l);
				IAreaFactory<LazyArea> parentLayer = IslandLayer.INSTANCE.apply(contextFactory.apply(1));
				IAreaFactory<LazyArea> biomeLayer = (new BiomeLayerCustom()).apply(contextFactory.apply(200), parentLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1000), biomeLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1001), biomeLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1002), biomeLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1003), biomeLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1004), biomeLayer);
				biomeLayer = ZoomLayer.NORMAL.apply(contextFactory.apply(1005), biomeLayer);
				return new Layer(biomeLayer);
			}
		}
}

 

Last seen on 02:25, 25. Apr 2021
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Btw, this mod is about ores
Sat, 08/15/2020 - 18:32

Btw, this mod is about ores

Last seen on 02:25, 25. Apr 2021
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I've tried regenerating code…
Sat, 08/15/2020 - 19:14

I've tried regenerating code, building code, cleaning code, and Clearing all caches, but they didn't work!

Last seen on 02:25, 25. Apr 2021
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Can a moderator remove this…
Sun, 08/16/2020 - 00:22

Can a moderator remove this topic. I realized that there's a bug support option thx!