mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Further BaseBlock modernisation
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.ItemRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@ -31,7 +32,7 @@ public class ForgeItemRegistry implements ItemRegistry {
|
||||
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);
|
||||
return new BaseItem(ItemTypes.getItemType(id));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -41,7 +42,7 @@ public class ForgeItemRegistry implements ItemRegistry {
|
||||
@Override
|
||||
public BaseItem createFromId(int id) {
|
||||
if (Item.REGISTRY.getObjectById(id) != null) {
|
||||
return new BaseItem(id, (short) 0);
|
||||
return new BaseItem(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,8 +91,9 @@ public class ForgePlayer extends AbstractPlayerActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0));
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
this.player.inventory.addItemStackToInventory(
|
||||
new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,7 +238,12 @@ public class ForgeWorld extends AbstractWorld {
|
||||
@Override
|
||||
public boolean useItem(Vector position, BaseItem item, Direction face) {
|
||||
Item nativeItem = Item.getByNameOrId(item.getType().getId());
|
||||
ItemStack stack = new ItemStack(nativeItem, 1, item.getData());
|
||||
ItemStack stack = null;
|
||||
if (item.getNbtData() == null) {
|
||||
stack = new ItemStack(nativeItem, 1, 0);
|
||||
} else {
|
||||
stack = new ItemStack(nativeItem, 1, 0, NBTConverter.toNative(item.getNbtData()));
|
||||
}
|
||||
World world = getWorld();
|
||||
EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position),
|
||||
EnumHand.MAIN_HAND, ForgeAdapter.adapt(face), 0, 0, 0);
|
||||
@ -333,7 +338,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
@Override
|
||||
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
|
||||
WorldGenerator generator = createWorldGenerator(type);
|
||||
return generator != null ? generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position)) : false;
|
||||
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -341,12 +346,6 @@ public class ForgeWorld extends AbstractWorld {
|
||||
return ForgeWorldData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int id) {
|
||||
Block block = Block.getBlockById(id);
|
||||
return Block.getIdFromBlock(block) == id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) {
|
||||
World world = getWorld();
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.block.Block;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static net.minecraft.block.Block.REGISTRY;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -30,12 +29,12 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
@ -54,9 +53,9 @@ import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static net.minecraft.block.Block.REGISTRY;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* The Forge implementation of WorldEdit.
|
||||
@ -214,12 +213,11 @@ public class ForgeWorldEdit {
|
||||
}
|
||||
|
||||
public static ItemStack toForgeItemStack(BaseItemStack item) {
|
||||
ItemStack ret = new ItemStack(Item.getByNameOrId(item.getType().getId()), item.getAmount(), item.getData());
|
||||
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
||||
ret.addEnchantment(net.minecraft.enchantment.Enchantment.getEnchantmentByID(entry.getKey()), entry.getValue());
|
||||
NBTTagCompound forgeCompound = null;
|
||||
if (item.getNbtData() != null) {
|
||||
forgeCompound = NBTConverter.toNative(item.getNbtData());
|
||||
}
|
||||
|
||||
return ret;
|
||||
return new ItemStack(Item.getByNameOrId(item.getType().getId()), item.getAmount(), 0, forgeCompound);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user