Permalink
Browse files

Further work on 1.13

  • Loading branch information...
me4502 committed Dec 29, 2018
1 parent 9de847c commit 8286c72a899fba62572ae8314905109389d05251
@@ -14,7 +14,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'

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

dependencies {
compile project(':worldedit-core')
@@ -20,7 +20,7 @@
package com.sk89q.worldedit.forge;

import com.sk89q.worldedit.forge.gui.GuiHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.network.NetworkRegistry;

public class CommonProxy {

@@ -20,6 +20,8 @@
package com.sk89q.worldedit.forge;

import com.google.common.collect.ImmutableList;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.BooleanProperty;
@@ -30,12 +32,24 @@
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World;

import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.IProperty;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.stream.Collectors;

@@ -110,4 +124,36 @@ public static BlockPos toBlockPos(BlockVector3 vector) {
return new IPropertyAdapter<>(property);
}

public static Block adapt(BlockType blockType) {
return ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockType.getId()));
}

public static BlockType adapt(Block block) {
return BlockTypes.get(ForgeRegistries.BLOCKS.getKey(block).toString());
}

public static Item adapt(ItemType itemType) {
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemType.getId()));
}

public static ItemType adapt(Item item) {
return ItemTypes.get(ForgeRegistries.ITEMS.getKey(item).toString());
}

public static ItemStack adapt(BaseItemStack baseItemStack) {
NBTTagCompound forgeCompound = null;
if (baseItemStack.getNbtData() != null) {
forgeCompound = NBTConverter.toNative(baseItemStack.getNbtData());
}
return new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount(), forgeCompound);
}

public static BaseItemStack adapt(ItemStack itemStack) {
CompoundTag tag = NBTConverter.fromNative(itemStack.serializeNBT());
return new BaseItemStack(adapt(itemStack.getItem()), tag, itemStack.getCount());
}

public static Biome adapt(BaseBiome biome) {
return Biome.getBiomeForId(biome.getId());
}
}
@@ -23,6 +23,7 @@
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.ArrayList;
import java.util.List;
@@ -40,7 +41,7 @@ public BaseBiome createFromId(int id) {
@Override
public List<BaseBiome> getBiomes() {
List<BaseBiome> list = new ArrayList<>();
for (Biome biome : Biome.REGISTRY) {
for (Biome biome : ForgeRegistries.BIOMES) {
list.add(new BaseBiome(Biome.getIdForBiome(biome)));
}
return list;
@@ -23,11 +23,9 @@
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;

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

import java.util.Collection;
import java.util.HashMap;
@@ -43,19 +41,29 @@
@Nullable
@Override
public String getName(BlockType blockType) {
return Block.REGISTRY.get(new ResourceLocation(blockType.getId())).getNameTextComponent().getFormattedText();
Block block = ForgeAdapter.adapt(blockType);
if (block != null) {
return block.getNameTextComponent().getFormattedText();
} else {
return super.getName(blockType);
}
}

@Override
public BlockMaterial getMaterial(BlockType blockType) {
return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(),
Block block = ForgeAdapter.adapt(blockType);
if (block == null) {
return super.getMaterial(blockType);
}
return materialMap.computeIfAbsent(block.getDefaultState().getMaterial(),
m -> new ForgeBlockMaterial(m, super.getMaterial(blockType)));
}

@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Block block = ForgeAdapter.adapt(blockType);
Map<String, Property<?>> map = new TreeMap<>();
Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId())
Collection<IProperty<?>> propertyKeys = block
.getDefaultState()
.getProperties();
for (IProperty<?> key : propertyKeys) {
@@ -29,7 +29,6 @@
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;

import java.lang.ref.WeakReference;
@@ -49,7 +48,7 @@
public BaseEntity getState() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
String id = EntityList.getEntityString(entity);
String id = entity.getType().getRegistryName().toString();
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeWithoutTypeId(tag);
@@ -23,6 +23,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.GameType;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import org.spongepowered.api.entity.living.player.Player;

public interface ForgePermissionsProvider {
@@ -43,7 +44,7 @@ public VanillaPermissionsProvider(ForgePlatform platform) {
public boolean hasPermission(EntityPlayerMP player, String permission) {
ForgeConfiguration configuration = platform.getConfiguration();
return configuration.cheatMode ||
FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().canSendCommands(player.getGameProfile()) ||
ServerLifecycleHooks.getCurrentServer().getPlayerList().canSendCommands(player.getGameProfile()) ||
(configuration.creativeEnable && player.interactionManager.getGameType() == GameType.CREATIVE);
}

@@ -37,7 +37,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.server.ServerLifecycleHooks;

import java.util.ArrayList;
import java.util.Collection;
@@ -55,7 +55,7 @@

ForgePlatform(ForgeWorldEdit mod) {
this.mod = mod;
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
this.server = ServerLifecycleHooks.getCurrentServer();
}

boolean isHookingEvents() {
@@ -69,7 +69,7 @@ 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(Item.REGISTRY.getKey(is.getItem()).toString()));
return ForgeAdapter.adapt(is);
}

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

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

@Override
Oops, something went wrong.

0 comments on commit 8286c72

Please sign in to comment.