Permalink
Browse files

Fixed a lot of the errors, still more to go. Gotta switch to Forge re…

…gistries once they exist.
  • Loading branch information...
me4502 committed Dec 26, 2018
1 parent fab684c commit 162bec1c5f2d5ab075f5ec9af5de44c415be2994
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'

def minecraftVersion = "1.13"
def forgeVersion = "24.0.32-1.13-pre"
def forgeVersion = "24.0.44-1.13-pre"

dependencies {
compile project(':worldedit-core')
@@ -29,6 +29,8 @@ targetCompatibility = 1.8

minecraft {
mappings channel: 'snapshot', version: '20180921-1.13'

accessTransformer = file('worldedit_at.cfg')
}

project.archivesBaseName = "${project.archivesBaseName}-mc${minecraftVersion}"
@@ -30,12 +30,10 @@
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World;

import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.IProperty;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

@@ -93,20 +91,20 @@ public static BlockPos toBlockPos(BlockVector3 vector) {
}

public static Property<?> adaptProperty(IProperty<?> property) {
if (property instanceof PropertyBool) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((PropertyBool) property).getAllowedValues()));
if (property instanceof net.minecraft.state.BooleanProperty) {
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.BooleanProperty) property).getAllowedValues()));
}
if (property instanceof PropertyInteger) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((PropertyInteger) property).getAllowedValues()));
if (property instanceof net.minecraft.state.IntegerProperty) {
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((net.minecraft.state.IntegerProperty) property).getAllowedValues()));
}
if (property instanceof PropertyDirection) {
return new DirectionalProperty(property.getName(), ((PropertyDirection) property).getAllowedValues().stream()
if (property instanceof DirectionProperty) {
return new DirectionalProperty(property.getName(), ((DirectionProperty) property).getAllowedValues().stream()
.map(ForgeAdapter::adaptEnumFacing)
.collect(Collectors.toList()));
}
if (property instanceof PropertyEnum) {
return new EnumProperty(property.getName(), ((PropertyEnum<?>) property).getAllowedValues().stream()
.map(e -> e.getName())
if (property instanceof net.minecraft.state.EnumProperty) {
return new EnumProperty(property.getName(), ((net.minecraft.state.EnumProperty<?>) property).getAllowedValues().stream()
.map(IStringSerializable::getName)
.collect(Collectors.toList()));
}
return new IPropertyAdapter<>(property);
@@ -68,7 +68,7 @@ private ForgeBiomeData(Biome biome) {

@Override
public String getName() {
return biome.getBiomeName();
return biome.getDisplayName().getString();
}
}

@@ -26,7 +26,7 @@

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.state.IProperty;
import net.minecraft.util.ResourceLocation;

import java.util.Collection;
@@ -43,7 +43,7 @@
@Nullable
@Override
public String getName(BlockType blockType) {
return Block.REGISTRY.getObject(new ResourceLocation(blockType.getId())).getLocalizedName();
return Block.REGISTRY.get(new ResourceLocation(blockType.getId())).getNameTextComponent().getFormattedText();
}

@Override
@@ -57,7 +57,7 @@ public BlockMaterial getMaterial(BlockType blockType) {
Map<String, Property<?>> map = new TreeMap<>();
Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId())
.getDefaultState()
.getPropertyKeys();
.getProperties();
for (IProperty<?> key : propertyKeys) {
map.put(key.getName(), ForgeAdapter.adaptProperty(key));
}
@@ -52,7 +52,7 @@ public BaseEntity getState() {
String id = EntityList.getEntityString(entity);
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
entity.writeWithoutTypeId(tag);
return new BaseEntity(EntityTypes.get(id), NBTConverter.fromNative(tag));
} else {
return null;
@@ -96,7 +96,7 @@ public Extent getExtent() {
public boolean remove() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
entity.setDead();
entity.remove();
}
return true;
}
@@ -41,10 +41,10 @@
import net.minecraft.network.play.server.SPacketCustomPayload;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.registry.ForgeRegistries;

import java.util.UUID;

@@ -69,12 +69,12 @@ public UUID getUniqueId() {
@Override
public BaseItemStack getItemInHand(HandSide handSide) {
ItemStack is = this.player.getHeldItem(handSide == HandSide.MAIN_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
return new BaseItemStack(ItemTypes.get(ForgeRegistries.ITEMS.getKey(is.getItem()).toString()));
return new BaseItemStack(ItemTypes.get(Item.REGISTRY.getKey(is.getItem()).toString()));
}

@Override
public String getName() {
return this.player.getName();
return this.player.getName().getFormattedText();
}

@Override
@@ -105,8 +105,7 @@ public boolean setLocation(Location location) {

@Override
public void giveItem(BaseItemStack itemStack) {
this.player.inventory.addItemStackToInventory(
new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0));
this.player.inventory.addItemStackToInventory(new ItemStack(Item.REGISTRY.get(new ResourceLocation(itemStack.getType().getId())), itemStack.getAmount(), null));
}

@Override
@@ -117,7 +116,7 @@ public void dispatchCUIEvent(CUIEvent event) {
send = send + "|" + StringUtil.joinString(params, "|");
}
PacketBuffer buffer = new PacketBuffer(Unpooled.copiedBuffer(send.getBytes(WECUIPacketHandler.UTF_8_CHARSET)));
SPacketCustomPayload packet = new SPacketCustomPayload(ForgeWorldEdit.CUI_PLUGIN_CHANNEL, buffer);
SPacketCustomPayload packet = new SPacketCustomPayload(new ResourceLocation(ForgeWorldEdit.CUI_PLUGIN_CHANNEL), buffer);
this.player.connection.sendPacket(packet);
}

@@ -197,7 +196,7 @@ public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {

@Override
public SessionKey getSessionKey() {
return new SessionKeyImpl(player.getUniqueID(), player.getName());
return new SessionKeyImpl(player.getUniqueID(), player.getName().getString());
}

private static class SessionKeyImpl implements SessionKey {
@@ -52,22 +52,17 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.IProperty;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
@@ -78,6 +73,7 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.chunk.storage.AnvilSaveHandler;
@@ -117,9 +113,9 @@
private static final Random random = new Random();
private static final int UPDATE = 1, NOTIFY = 2;

private static final IBlockState JUNGLE_LOG = Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE);
private static final IBlockState JUNGLE_LEAF = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
private static final IBlockState JUNGLE_SHRUB = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
private static final IBlockState JUNGLE_LOG = Blocks.JUNGLE_LOG.getDefaultState();
private static final IBlockState JUNGLE_LEAF = Blocks.JUNGLE_LEAVES.getDefaultState().with(BlockLeaves.PERSISTENT, Boolean.TRUE);
private static final IBlockState JUNGLE_SHRUB = Blocks.OAK_LEAVES.getDefaultState().with(BlockLeaves.PERSISTENT, Boolean.TRUE);

private final WeakReference<World> worldRef;

@@ -179,7 +175,7 @@ public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean n
int z = position.getBlockZ();

// First set the block
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
Chunk chunk = world.getChunk(x >> 4, z >> 4);
BlockPos pos = new BlockPos(x, y, z);
IBlockState old = chunk.getBlockState(pos);
Block mcBlock = Block.getBlockFromName(block.getBlockType().getId());
@@ -226,17 +222,17 @@ private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockSt
IProperty property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof PropertyDirection) {
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = ForgeAdapter.adapt(dir);
} else if (property instanceof PropertyEnum) {
} else if (property instanceof EnumProperty) {
String enumName = (String) value;
value = ((PropertyEnum<?>) property).parseValue((String) value).or(() -> {
value = ((EnumProperty<?>) property).parseValue((String) value).orElseGet(() -> {
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
});
}

newState = newState.withProperty(property, value);
newState = newState.with(property, value);
}
return newState;
}
@@ -273,7 +269,7 @@ public boolean setBiome(BlockVector2 position, BaseBiome biome) {
checkNotNull(position);
checkNotNull(biome);

Chunk chunk = getWorld().getChunkFromBlockCoords(new BlockPos(position.getBlockX(), 0, position.getBlockZ()));
Chunk chunk = getWorld().getChunk(new BlockPos(position.getBlockX(), 0, position.getBlockZ()));
if (chunk.isLoaded()) {
chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) biome.getId();
return true;
@@ -284,12 +280,12 @@ public boolean setBiome(BlockVector2 position, BaseBiome biome) {

@Override
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
Item nativeItem = Item.getByNameOrId(item.getType().getId());
Item nativeItem = Item.REGISTRY.get(new ResourceLocation(item.getType().getId()));
ItemStack stack = null;
if (item.getNbtData() == null) {
stack = new ItemStack(nativeItem, 1, 0);
stack = new ItemStack(nativeItem, 1);
} else {
stack = new ItemStack(nativeItem, 1, 0, NBTConverter.toNative(item.getNbtData()));
stack = new ItemStack(nativeItem, 1, NBTConverter.toNative(item.getNbtData()));
}
World world = getWorld();
EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position),
@@ -335,16 +331,15 @@ public boolean regenerate(Region region, EditSession editSession) {
WorldServer originalWorld = (WorldServer) getWorld();

MinecraftServer server = originalWorld.getMinecraftServer();
AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder,
originalWorld.getSaveHandler().getWorldDirectory().getName(), true, server.getDataFixer());
AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), true, server.getDataFixer());
World freshWorld = new WorldServer(server, saveHandler, originalWorld.getWorldInfo(),
originalWorld.provider.getDimension(), originalWorld.profiler).init();
originalWorld.dimension.getId(), originalWorld.profiler).init();

// Pre-gen all the chunks
// We need to also pull one more chunk in every direction
CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
for (BlockVector2 chunk : expandedPreGen.getChunks()) {
freshWorld.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ());
freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
}

ForgeWorld from = new ForgeWorld(freshWorld);
@@ -356,8 +351,8 @@ public boolean regenerate(Region region, EditSession editSession) {
throw new RuntimeException(e);
} finally {
saveFolder.delete();
DimensionManager.setWorld(originalWorld.provider.getDimension(), null, server);
DimensionManager.setWorld(originalWorld.provider.getDimension(), originalWorld, server);
DimensionManager.setWorld(originalWorld.dimension.getId(), null, server);
DimensionManager.setWorld(originalWorld.dimension.getId(), originalWorld, server);
}

return true;
@@ -398,7 +393,7 @@ public boolean generateTree(TreeType type, EditSession editSession, BlockVector3

@Override
public void checkLoadedChunk(BlockVector3 pt) {
getWorld().getChunkFromBlockCoords(ForgeAdapter.toBlockPos(pt));
getWorld().getChunk(ForgeAdapter.toBlockPos(pt));
}

@Override
@@ -410,7 +405,7 @@ public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
public void fixLighting(Iterable<BlockVector2> chunks) {
World world = getWorld();
for (BlockVector2 chunk : chunks) {
world.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ()).resetRelightChecks();
world.getChunk(chunk.getBlockX(), chunk.getBlockZ()).resetRelightChecks();
}
}

@@ -441,7 +436,7 @@ public long getRemainingWeatherDuration() {
if (info.isRaining()) {
return info.getRainTime();
}
return info.getCleanWeatherTime();
return info.getClearWeatherTime();
}

@Override
@@ -453,17 +448,17 @@ public void setWeather(WeatherType weatherType) {
public void setWeather(WeatherType weatherType, long duration) {
WorldInfo info = getWorld().getWorldInfo();
if (WeatherTypes.THUNDER_STORM.equals(weatherType)) {
info.setCleanWeatherTime(0);
info.setClearWeatherTime(0);
info.setThundering(true);
info.setThunderTime((int) duration);
} else if (WeatherTypes.RAIN.equals(weatherType)) {
info.setCleanWeatherTime(0);
info.setClearWeatherTime(0);
info.setRaining(true);
info.setRainTime((int) duration);
} else if (WeatherTypes.CLEAR.equals(weatherType)) {
info.setRaining(false);
info.setThundering(false);
info.setCleanWeatherTime((int) duration);
info.setClearWeatherTime((int) duration);
}
}

@@ -478,17 +473,17 @@ public BlockState getBlock(BlockVector3 position) {
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
IBlockState mcState = world.getBlockState(pos);

BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getNameForObject(mcState.getBlock()).toString());
BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getKey(mcState.getBlock()).toString());
return blockType.getState(adaptProperties(blockType, mcState.getProperties()));
}

private Map<Property<?>, Object> adaptProperties(BlockType block, Map<IProperty<?>, Comparable<?>> mcProps) {
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
for (Map.Entry<IProperty<?>, Comparable<?>> prop : mcProps.entrySet()) {
Object value = prop.getValue();
if (prop.getKey() instanceof PropertyDirection) {
if (prop.getKey() instanceof DirectionProperty) {
value = ForgeAdapter.adaptEnumFacing((EnumFacing) value);
} else if (prop.getKey() instanceof PropertyEnum) {
} else if (prop.getKey() instanceof EnumProperty) {
value = ((IStringSerializable) value).getName();
}
props.put(block.getProperty(prop.getKey().getName()), value);
@@ -561,7 +556,7 @@ public Entity createEntity(Location location, BaseEntity entity) {
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.removeTag(name);
}
createdEntity.readFromNBT(tag);
createdEntity.read(tag);
}

createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Oops, something went wrong.

0 comments on commit 162bec1

Please sign in to comment.