Re-add and update ForgeItemRegistry.

And fix code that depended on it.
Reverts parts of e91859130c
This commit is contained in:
wizjany 2016-08-28 02:48:29 -04:00
parent 2267dfd29f
commit ddff8ecbb2
4 changed files with 98 additions and 33 deletions

View File

@ -20,8 +20,9 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -46,6 +47,19 @@ final class ForgeAdapter {
return new Vec3d(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return new Vec3d(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
} }
public static EnumFacing adapt(Direction face) {
switch (face) {
case NORTH: return EnumFacing.NORTH;
case SOUTH: return EnumFacing.SOUTH;
case WEST: return EnumFacing.WEST;
case EAST: return EnumFacing.EAST;
case DOWN: return EnumFacing.DOWN;
case UP:
default:
return EnumFacing.UP;
}
}
public static BlockPos toBlockPos(Vector vector) { public static BlockPos toBlockPos(Vector vector) {
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
} }

View File

@ -0,0 +1,49 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
public class ForgeItemRegistry implements ItemRegistry {
@Nullable
@Override
public BaseItem createFromId(String id) {
Item match = Item.REGISTRY.getObject(new ResourceLocation(id));
if (match != null) {
return new BaseItem(Item.REGISTRY.getIDForObject(match), (short) 0);
} else {
return null;
}
}
@Nullable
@Override
public BaseItem createFromId(int id) {
if (Item.REGISTRY.getObjectById(id) != null) {
return new BaseItem(id, (short) 0);
} else {
return null;
}
}
}

View File

@ -20,47 +20,36 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.LazyBlock; import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.WorldData; import com.sk89q.worldedit.world.registry.WorldData;
import net.minecraft.block.*;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
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.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMap;
import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -70,19 +59,15 @@ import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkGenerator; import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer; import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.WorldGenBigMushroom; import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenBirchTree; import javax.annotation.Nullable;
import net.minecraft.world.gen.feature.WorldGenCanopyTree; import java.lang.ref.WeakReference;
import net.minecraft.world.gen.feature.WorldGenMegaJungle; import java.util.ArrayList;
import net.minecraft.world.gen.feature.WorldGenMegaPineTree; import java.util.List;
import net.minecraft.world.gen.feature.WorldGenSavannaTree; import java.util.Random;
import net.minecraft.world.gen.feature.WorldGenShrub; import java.util.logging.Level;
import net.minecraft.world.gen.feature.WorldGenSwamp; import java.util.logging.Logger;
import net.minecraft.world.gen.feature.WorldGenTaiga1;
import net.minecraft.world.gen.feature.WorldGenTaiga2;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -227,6 +212,16 @@ public class ForgeWorld extends AbstractWorld {
return false; return false;
} }
@Override
public boolean useItem(Vector position, BaseItem item, Direction face) {
Item nativeItem = Item.getItemById(item.getType());
ItemStack stack = new ItemStack(nativeItem, 1, item.getData());
World world = getWorld();
EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position),
EnumHand.MAIN_HAND, ForgeAdapter.adapt(face), 0, 0, 0);
return used != EnumActionResult.FAIL;
}
@Override @Override
public void dropItem(Vector position, BaseItemStack item) { public void dropItem(Vector position, BaseItemStack item) {
checkNotNull(position); checkNotNull(position);

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import com.sk89q.worldedit.world.registry.LegacyWorldData; import com.sk89q.worldedit.world.registry.LegacyWorldData;
/** /**
@ -29,12 +30,18 @@ class ForgeWorldData extends LegacyWorldData {
private static final ForgeWorldData INSTANCE = new ForgeWorldData(); private static final ForgeWorldData INSTANCE = new ForgeWorldData();
private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry(); private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry();
private final ItemRegistry itemRegistry = new ForgeItemRegistry();
@Override @Override
public BiomeRegistry getBiomeRegistry() { public BiomeRegistry getBiomeRegistry() {
return biomeRegistry; return biomeRegistry;
} }
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
/** /**
* Get a static instance. * Get a static instance.
* *