Upstream and some refactoring

Note: Maybe this doesn't compile, ij is broken af smh, let's give it a try...
This commit is contained in:
NotMyFault
2020-01-04 18:34:30 +01:00
parent 0bf6cfad8d
commit b292416496
29 changed files with 1556 additions and 805 deletions

View File

@ -114,6 +114,23 @@ public final class BundledItemData {
return idMap.get(id);
}
/**
* Get the material properties for the given item.
*
* @param id the string ID
* @return the material's properties, or null
*/
@Nullable
public ItemMaterial getMaterialById(String id) {
ItemEntry entry = findById(id);
if (entry != null) {
// FIXME: This should probably just be part of the JSON itself
return new SimpleItemMaterial(entry.maxStackSize, entry.maxDamage);
} else {
return null;
}
}
/**
* Get a singleton instance of this object.
*

View File

@ -29,14 +29,18 @@ import javax.annotation.Nullable;
*/
public class BundledItemRegistry implements ItemRegistry {
private BundledItemData.ItemEntry getEntryById(ItemType itemType) {
return BundledItemData.getInstance().findById(itemType.getId());
}
@Nullable
@Override
public String getName(ItemType itemType) {
String id = itemType.getId();
BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(id);
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
if (itemEntry != null) {
String localized = itemEntry.localizedName;
if (localized.equals("Air")) {
String id = itemType.getId();
int c = id.indexOf(':');
return c < 0 ? id : id.substring(c + 1);
}
@ -44,4 +48,10 @@ public class BundledItemRegistry implements ItemRegistry {
}
return null;
}
@Nullable
@Override
public ItemMaterial getMaterial(ItemType itemType) {
return new PassthroughItemMaterial(BundledItemData.getInstance().getMaterialById(itemType.getId()));
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.world.registry;
public interface ItemMaterial {
/**
* Gets the the maximum quantity of this item that can be in a single stack.
*
* @return the maximum quantity
*/
int getMaxStackSize();
/**
* Gets the the maximum damage this item can take before being broken.
*
* @return the maximum damage, or 0 if not applicable
*/
int getMaxDamage();
}

View File

@ -36,6 +36,15 @@ public interface ItemRegistry {
@Nullable
String getName(ItemType itemType);
/**
* Get the material for the given item.
*
* @param itemType the item
* @return the material, or null if the material information is not known
*/
@Nullable
ItemMaterial getMaterial(ItemType itemType);
/**
* Register all items
*/

View File

@ -21,21 +21,31 @@ package com.sk89q.worldedit.world.registry;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;
public class PassthroughBlockMaterial implements BlockMaterial {
@Nullable private final BlockMaterial blockMaterial;
private static final SimpleBlockMaterial DEFAULT_MATERIAL = new SimpleBlockMaterial();
static {
DEFAULT_MATERIAL.setFullCube(true);
DEFAULT_MATERIAL.setOpaque(true);
DEFAULT_MATERIAL.setSolid(true);
DEFAULT_MATERIAL.setTicksRandomly(true);
DEFAULT_MATERIAL.setMovementBlocker(true);
DEFAULT_MATERIAL.setBurnable(true);
DEFAULT_MATERIAL.setToolRequired(true);
}
private final BlockMaterial blockMaterial;
public PassthroughBlockMaterial(@Nullable BlockMaterial material) {
this.blockMaterial = material;
this.blockMaterial = firstNonNull(material, DEFAULT_MATERIAL);
}
@Override
public boolean isAir() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAir();
}
return blockMaterial.isAir();
}
@Override
@ -49,172 +59,96 @@ public class PassthroughBlockMaterial implements BlockMaterial {
@Override
public boolean isFullCube() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isFullCube();
}
return blockMaterial.isFullCube();
}
@Override
public boolean isOpaque() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isOpaque();
}
return blockMaterial.isOpaque();
}
@Override
public boolean isPowerSource() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isPowerSource();
}
return blockMaterial.isPowerSource();
}
@Override
public boolean isLiquid() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isLiquid();
}
return blockMaterial.isLiquid();
}
@Override
public boolean isSolid() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isSolid();
}
return blockMaterial.isSolid();
}
@Override
public float getHardness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getHardness();
}
return blockMaterial.getHardness();
}
@Override
public float getResistance() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getResistance();
}
return blockMaterial.getResistance();
}
@Override
public float getSlipperiness() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getSlipperiness();
}
return blockMaterial.getSlipperiness();
}
@Override
public int getLightValue() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightValue();
}
return blockMaterial.getLightValue();
}
@Override
public int getLightOpacity() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightOpacity();
}
return blockMaterial.getLightOpacity();
}
@Override
public boolean isFragileWhenPushed() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isFragileWhenPushed();
}
return blockMaterial.isFragileWhenPushed();
}
@Override
public boolean isUnpushable() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isUnpushable();
}
return blockMaterial.isUnpushable();
}
@Override
public boolean isTicksRandomly() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isTicksRandomly();
}
return blockMaterial.isTicksRandomly();
}
@Override
public boolean isMovementBlocker() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isMovementBlocker();
}
return blockMaterial.isMovementBlocker();
}
@Override
public boolean isBurnable() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isBurnable();
}
return blockMaterial.isBurnable();
}
@Override
public boolean isToolRequired() {
if (blockMaterial == null) {
return true;
} else {
return blockMaterial.isToolRequired();
}
return blockMaterial.isToolRequired();
}
@Override
public boolean isReplacedDuringPlacement() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isReplacedDuringPlacement();
}
return blockMaterial.isReplacedDuringPlacement();
}
@Override
public boolean isTranslucent() {
if (blockMaterial == null) {
return !isOpaque();
} else {
return blockMaterial.isTranslucent();
}
return blockMaterial.isTranslucent();
}
@Override
public boolean hasContainer() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.hasContainer();
}
return blockMaterial.hasContainer();
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.world.registry;
import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;
import javax.annotation.Nullable;
public class PassthroughItemMaterial implements ItemMaterial {
private static final ItemMaterial DEFAULT_MATERIAL = new SimpleItemMaterial(0, 0);
private final ItemMaterial itemMaterial;
public PassthroughItemMaterial(@Nullable ItemMaterial material) {
this.itemMaterial = firstNonNull(material, DEFAULT_MATERIAL);
}
@Override
public int getMaxStackSize() {
return itemMaterial.getMaxStackSize();
}
@Override
public int getMaxDamage() {
return itemMaterial.getMaxDamage();
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.world.registry;
class SimpleItemMaterial implements ItemMaterial {
private int maxStackSize;
private int maxDamage;
public SimpleItemMaterial(int maxStackSize, int maxDamage) {
this.maxStackSize = maxStackSize;
this.maxDamage = maxDamage;
}
@Override
public int getMaxStackSize() {
return maxStackSize;
}
@Override
public int getMaxDamage() {
return maxDamage;
}
}