Added an entity, weathertype, and gamemode registry.

This commit is contained in:
Matthew Miller
2018-07-19 22:41:26 +10:00
parent 572bf04482
commit 663dd1f4d8
33 changed files with 747 additions and 115 deletions

View File

@ -22,10 +22,11 @@ package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.entity.EntityTypes;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
@ -40,7 +41,7 @@ class ForgeEntity implements Entity {
ForgeEntity(net.minecraft.entity.Entity entity) {
checkNotNull(entity);
this.entityRef = new WeakReference<net.minecraft.entity.Entity>(entity);
this.entityRef = new WeakReference<>(entity);
}
@Override
@ -51,7 +52,7 @@ class ForgeEntity implements Entity {
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
return new BaseEntity(id, NBTConverter.fromNative(tag));
return new BaseEntity(EntityTypes.get(id), NBTConverter.fromNative(tag));
} else {
return null;
}
@ -99,8 +100,8 @@ class ForgeEntity implements Entity {
public <T> T getFacet(Class<? extends T> cls) {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
if (EntityType.class.isAssignableFrom(cls)) {
return (T) new ForgeEntityType(entity);
if (EntityProperties.class.isAssignableFrom(cls)) {
return (T) new ForgeEntityProperties(entity);
} else {
return null;
}

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IMerchant;
@ -45,11 +45,11 @@ import net.minecraft.entity.player.EntityPlayerMP;
import static com.google.common.base.Preconditions.checkNotNull;
public class ForgeEntityType implements EntityType {
public class ForgeEntityProperties implements EntityProperties {
private final Entity entity;
public ForgeEntityType(Entity entity) {
public ForgeEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}

View File

@ -47,6 +47,7 @@ import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.weather.WeatherType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockOldLeaf;
@ -350,6 +351,27 @@ public class ForgeWorld extends AbstractWorld {
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
}
@Override
public WeatherType getWeather() {
// TODO Weather implementation
return null;
}
@Override
public long getRemainingWeatherDuration() {
return 0;
}
@Override
public void setWeather(WeatherType weatherType) {
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
}
@Override
public BlockState getBlock(Vector position) {
World world = getWorld();
@ -421,7 +443,7 @@ public class ForgeWorld extends AbstractWorld {
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getTypeId()), world);
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) {