Clean-up some misc. parts of the code

Dieser Commit ist enthalten in:
Kenzie Togami 2019-05-23 22:19:25 -07:00 committet von Matthew Miller
Ursprung dc21b4df58
Commit 8c17aab9c5
6 geänderte Dateien mit 26 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -413,6 +413,8 @@ public class BukkitWorld extends AbstractWorld {
getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally(); getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
} }
private static volatile boolean hasWarnedImplError = false;
@Override @Override
public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) { public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
@ -420,13 +422,14 @@ public class BukkitWorld extends AbstractWorld {
try { try {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toImmutableState(); return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toImmutableState();
} catch (Exception e) { } catch (Exception e) {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); if (!hasWarnedImplError) {
return BukkitAdapter.adapt(bukkitBlock.getBlockData()); hasWarnedImplError = true;
logger.warn("Unable to retrieve block via impl adapter", e);
}
} }
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
} }
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return BukkitAdapter.adapt(bukkitBlock.getBlockData());
} }
@Override @Override

Datei anzeigen

@ -65,7 +65,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
this.values = new LinkedHashMap<>(); this.values = new LinkedHashMap<>();
this.emptyBaseBlock = new BaseBlock(this); this.emptyBaseBlock = new BaseBlock(this);
} }
BlockState initializeId(BlockRegistry registry) { BlockState initializeId(BlockRegistry registry) {
this.internalId = registry.getInternalBlockStateId(this); this.internalId = registry.getInternalBlockStateId(this);
return this; return this;

Datei anzeigen

@ -73,5 +73,6 @@ public interface BlockRegistry {
* @param id The internal ID * @param id The internal ID
* @return the block state, if available * @return the block state, if available
*/ */
@Nullable
BlockState getBlockStateByInternalId(int id); BlockState getBlockStateByInternalId(int id);
} }

Datei anzeigen

@ -19,8 +19,6 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
@ -63,6 +61,8 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
public final class ForgeAdapter { public final class ForgeAdapter {
private ForgeAdapter() { private ForgeAdapter() {

Datei anzeigen

@ -27,8 +27,11 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.state.IProperty; import net.minecraft.state.IProperty;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.GameData;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -40,6 +43,7 @@ import javax.annotation.Nullable;
public class ForgeBlockRegistry extends BundledBlockRegistry { public class ForgeBlockRegistry extends BundledBlockRegistry {
private final int airId = Block.getStateId(Blocks.AIR.getDefaultState());
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>(); private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
@Nullable @Nullable
@ -82,4 +86,13 @@ public class ForgeBlockRegistry extends BundledBlockRegistry {
return OptionalInt.of(Block.getStateId(equivalent)); return OptionalInt.of(Block.getStateId(equivalent));
} }
@Override
public BlockState getBlockStateByInternalId(int id) {
IBlockState equivalent = Block.getStateById(id);
if (equivalent.equals(Blocks.AIR.getDefaultState()) && id != airId) {
// We didn't find a match.
return null;
}
return ForgeAdapter.adapt(equivalent);
}
} }

Datei anzeigen

@ -175,9 +175,6 @@ public class ForgeWorldEdit {
ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString())); ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString()));
} }
} }
config = new ForgeConfiguration(this);
config.load();
} }
@SubscribeEvent @SubscribeEvent
@ -211,7 +208,7 @@ public class ForgeWorldEdit {
InternalPacketHandler.getHandler().sendToServer(new LeftClickAirEventMessage()); InternalPacketHandler.getHandler().sendToServer(new LeftClickAirEventMessage());
return; return;
} }
boolean isLeftDeny = event instanceof PlayerInteractEvent.LeftClickBlock boolean isLeftDeny = event instanceof PlayerInteractEvent.LeftClickBlock
&& ((PlayerInteractEvent.LeftClickBlock) event) && ((PlayerInteractEvent.LeftClickBlock) event)
.getUseItem() == Event.Result.DENY; .getUseItem() == Event.Result.DENY;