Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove metadata casts to byte #3706

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/bartworks/API/GlassTier.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public static void addCustomGlass(String modname, String unlocalisedBlockName, i

public static void addCustomGlass(@NotNull Block block, int meta, int tier) {
Objects.requireNonNull(block, "Glass block cannot be null");
GlassTier.glasses.put(new BlockMetaPair(block, (byte) meta), tier);
GlassTier.glasses.put(new BlockMetaPair(block, meta), tier);
}

public static HashMap<BlockMetaPair, Integer> getGlassMap() {
return glasses;
}

public static int getGlassTier(Block block, int meta) {
return glasses.getOrDefault(new BlockMetaPair(block, (byte) meta), 0);
return glasses.getOrDefault(new BlockMetaPair(block, meta), 0);
}

public static class BlockMetaPair {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) {
int tY = MathHelper.floor_double(aItemEntity.posY);
int tZ = MathHelper.floor_double(aItemEntity.posZ);
Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ);
byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
if (tBlock == Blocks.cauldron && tMetaData > 0) {
if (this.orePrefixes == OrePrefixes.dustImpure || this.orePrefixes == OrePrefixes.dustPure) {
aItemEntity.setEntityItemStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ public boolean isMiningTool() {
return false;
}

public boolean isMinableBlock(Block aBlock, byte aMetaData) {
public boolean isMinableBlock(Block aBlock, int aMetaData) {

return false;
}

@Override
public int convertBlockDrops(List<ItemStack> list, ItemStack itemStack, EntityPlayer entityPlayer, Block block,
int i, int i1, int i2, byte b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) {
int i, int i1, int i2, int b, int i3, boolean b1, BlockEvent.HarvestDropsEvent harvestDropsEvent) {
return 0;
}

Expand Down Expand Up @@ -193,8 +193,9 @@ public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase
+ EnumChatFormatting.WHITE);
}

public float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld,
int aX, int aY, int aZ) {
@Override
public float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World aWorld, int aX,
int aY, int aZ) {
return aDefault;
}
}
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/interfaces/IBlockContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface IBlockContainer {

Block getBlock();

byte getMeta();
int getMeta();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface IRedstoneCircuitBlock {
/**
* returns whatever Meta-Value is adjacent to the Redstone Circuit Block
*/
byte getMetaIDAtSide(ForgeDirection side);
int getMetaIDAtSide(ForgeDirection side);

/**
* returns whatever TileEntity is adjacent to the Redstone Circuit Block
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/api/interfaces/IToolStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface IToolStats {
* @param tile TileEntity of the block if exist
* @param event the event, cancel it to prevent the block from being broken
*/
default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, byte metadata,
default void onBreakBlock(@Nonnull EntityPlayer player, int x, int y, int z, @Nonnull Block block, int metadata,
@Nullable TileEntity tile, @Nonnull BlockEvent.BreakEvent event) {}

/**
Expand Down Expand Up @@ -164,15 +164,15 @@ default boolean isScrewdriver() {
* @return If this is a minable Block. Tool Quality checks (like Diamond Tier or something) are separate from this
* check.
*/
boolean isMinableBlock(Block aBlock, byte aMetaData);
boolean isMinableBlock(Block aBlock, int aMetaData);

/**
* This lets you modify the Drop List, when this type of Tool has been used.
*
* @return the Amount of modified Items, used to determine the extra durability cost
*/
int convertBlockDrops(List<ItemStack> aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY,
int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent);
int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent);

/**
* @return Returns a broken Version of the Item.
Expand All @@ -193,7 +193,7 @@ int convertBlockDrops(List<ItemStack> aDrops, ItemStack aStack, EntityPlayer aPl

short[] getRGBa(boolean aIsToolHead, ItemStack aStack);

float getMiningSpeed(Block aBlock, byte aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX,
float getMiningSpeed(Block aBlock, int aMetaData, float aDefault, EntityPlayer aPlayer, World worldObj, int aX,
int aY, int aZ);

default String getToolTypeName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ default ChunkCoordinates getCoords() {

Block getBlockAtSideAndDistance(ForgeDirection side, int aDistance);

byte getMetaID(int aX, int aY, int aZ);
int getMetaID(int aX, int aY, int aZ);

byte getMetaIDOffset(int aX, int aY, int aZ);
int getMetaIDOffset(int aX, int aY, int aZ);

byte getMetaIDAtSide(ForgeDirection side);
int getMetaIDAtSide(ForgeDirection side);

byte getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance);
int getMetaIDAtSideAndDistance(ForgeDirection side, int aDistance);

byte getLightLevel(int aX, int aY, int aZ);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/api/items/MetaGeneratedTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public final ItemStack getToolWithStats(int aToolID, int aAmount, Materials aPri
*/
@Mod.EventHandler
public void onHarvestBlockEvent(ArrayList<ItemStack> aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock,
int aX, int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) {
int aX, int aY, int aZ, int aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent) {
IToolStats tStats = getToolStats(aStack);
if (isItemStackUsable(aStack) && getDigSpeed(aStack, aBlock, aMetaData) > 0.0F) doDamage(
aStack,
Expand All @@ -266,7 +266,7 @@ public void onHarvestBlockEvent(ArrayList<ItemStack> aDrops, ItemStack aStack, E

@Mod.EventHandler
public float onBlockBreakSpeedEvent(float aDefault, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX,
int aY, int aZ, byte aMetaData, PlayerEvent.BreakSpeed aEvent) {
int aY, int aZ, int aMetaData, PlayerEvent.BreakSpeed aEvent) {
IToolStats tStats = getToolStats(aStack);
return tStats == null ? aDefault
: tStats.getMiningSpeed(aBlock, aMetaData, aDefault, aPlayer, aPlayer.worldObj, aX, aY, aZ);
Expand Down Expand Up @@ -695,14 +695,14 @@ public float getDigSpeed(ItemStack aStack, Block aBlock, int aMetaData) {
if (!isItemStackUsable(aStack)) return 0.0F;
IToolStats tStats = getToolStats(aStack);
if (tStats == null || Math.max(0, getHarvestLevel(aStack, "")) < aBlock.getHarvestLevel(aMetaData)) return 0.0F;
return tStats.isMinableBlock(aBlock, (byte) aMetaData)
return tStats.isMinableBlock(aBlock, aMetaData)
? Math.max(Float.MIN_NORMAL, tStats.getSpeedMultiplier() * getPrimaryMaterial(aStack).mToolSpeed)
: 0.0F;
}

@Override
public final boolean canHarvestBlock(Block aBlock, ItemStack aStack) {
return getDigSpeed(aStack, aBlock, (byte) 0) > 0.0F;
return getDigSpeed(aStack, aBlock, 0) > 0.0F;
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/gregtech/api/metatileentity/BaseTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ public final Block getBlockAtSideAndDistance(ForgeDirection side, int distance)
}

@Override
public final byte getMetaIDOffset(int x, int y, int z) {
public final int getMetaIDOffset(int x, int y, int z) {
return getMetaID(xCoord + x, yCoord + y, zCoord + z);
}

@Override
public final byte getMetaIDAtSide(ForgeDirection side) {
public final int getMetaIDAtSide(ForgeDirection side) {
return getMetaIDAtSideAndDistance(side, 1);
}

@Override
public final byte getMetaIDAtSideAndDistance(ForgeDirection side, int distance) {
public final int getMetaIDAtSideAndDistance(ForgeDirection side, int distance) {
return getMetaID(getOffsetX(side, distance), getOffsetY(side, distance), getOffsetZ(side, distance));
}

Expand Down Expand Up @@ -404,9 +404,9 @@ public Block getBlock(ChunkCoordinates aCoords) {
}

@Override
public final byte getMetaID(int x, int y, int z) {
public final int getMetaID(int x, int y, int z) {
if (ignoreUnloadedChunks && crossedChunkBorder(x, z) && !worldObj.blockExists(x, y, z)) return 0;
return (byte) worldObj.getBlockMetadata(x, y, z);
return worldObj.getBlockMetadata(x, y, z);
}

@Override
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/gregtech/api/util/GTBlockMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

import net.minecraft.block.Block;

import gnu.trove.map.TByteObjectMap;
import gnu.trove.map.hash.TByteObjectHashMap;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;

public class GTBlockMap<V> {

public static final byte WILDCARD = -1;
private final ConcurrentHashMap<Block, TByteObjectMap<V>> backing = new ConcurrentHashMap<>();
public static final int WILDCARD = -1;
private final ConcurrentHashMap<Block, TIntObjectMap<V>> backing = new ConcurrentHashMap<>();
private int size = 0;

private TByteObjectMap<V> getSubmap(Block block) {
return backing.computeIfAbsent(block, b -> new TByteObjectHashMap<>());
private TIntObjectMap<V> getSubmap(Block block) {
return backing.computeIfAbsent(block, b -> new TIntObjectHashMap<>());
}

/**
Expand All @@ -25,7 +25,7 @@ private TByteObjectMap<V> getSubmap(Block block) {
* @param meta meta
* @return old mapping, or null if that doesn't exist
*/
public V put(Block block, byte meta, V value) {
public V put(Block block, int meta, V value) {
V v = getSubmap(block).put(meta, value);
if (v == null) size++;
return v;
Expand All @@ -38,7 +38,7 @@ public V put(Block block, byte meta, V value) {
* @param meta meta
* @return old mapping, or null if that doesn't exist
*/
public V putIfAbsent(Block block, byte meta, V value) {
public V putIfAbsent(Block block, int meta, V value) {
V v = getSubmap(block).putIfAbsent(meta, value);
if (v == null) size++;
return v;
Expand All @@ -51,8 +51,8 @@ public V putIfAbsent(Block block, byte meta, V value) {
* @param meta meta
* @return old mapping, or null if that doesn't exist
*/
public V computeIfAbsent(Block block, byte meta, BiFunction<Block, Byte, V> function) {
TByteObjectMap<V> submap = getSubmap(block);
public V computeIfAbsent(Block block, int meta, BiFunction<Block, Integer, V> function) {
TIntObjectMap<V> submap = getSubmap(block);
V v = submap.get(meta);
if (v == null) {
v = function.apply(block, meta);
Expand All @@ -69,8 +69,8 @@ public V computeIfAbsent(Block block, byte meta, BiFunction<Block, Byte, V> func
* @param meta meta
* @return current mapping OR wildcard of that mapping exists
*/
public boolean containsKey(Block block, byte meta) {
TByteObjectMap<V> submap = backing.get(block);
public boolean containsKey(Block block, int meta) {
TIntObjectMap<V> submap = backing.get(block);
if (submap == null) return false;
return submap.containsKey(meta) || submap.containsKey(WILDCARD);
}
Expand All @@ -82,8 +82,8 @@ public boolean containsKey(Block block, byte meta) {
* @param meta meta
* @return current mapping OR wildcard of that block. null if neither exists
*/
public V get(Block block, byte meta) {
TByteObjectMap<V> submap = backing.get(block);
public V get(Block block, int meta) {
TIntObjectMap<V> submap = backing.get(block);
if (submap == null) return null;
V v = submap.get(meta);
if (v != null) return v;
Expand All @@ -97,8 +97,8 @@ public V get(Block block, byte meta) {
* @param meta meta
* @return old value, or null if none
*/
public V remove(Block block, byte meta) {
TByteObjectMap<V> submap = backing.get(block);
public V remove(Block block, int meta) {
TIntObjectMap<V> submap = backing.get(block);
if (submap == null) return null;
V v = submap.remove(meta);
if (v != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/util/GTBlockSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ public class GTBlockSet {

private final GTBlockMap<Object> backing = new GTBlockMap<>();

public boolean add(Block block, byte meta) {
public boolean add(Block block, int meta) {
return backing.put(block, meta, this) != this;
}

public boolean contains(Block block, byte meta) {
public boolean contains(Block block, int meta) {
return backing.get(block, meta) == this;
}

public boolean remove(Block block, byte meta) {
public boolean remove(Block block, int meta) {
return backing.remove(block, meta) == this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/util/GTToolHarvestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class GTToolHarvestHelper {

public static boolean isAppropriateTool(Block aBlock, byte aMetaData, String... tTools) {
public static boolean isAppropriateTool(Block aBlock, int aMetaData, String... tTools) {

if (aBlock == null || tTools == null) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -2527,15 +2527,15 @@ public static int getTextureId(byte page, byte startIndex, byte blockMeta) {
*
* @return casing texture 0 to 16383
*/
public static int getTextureId(Block blockFromBlock, byte metaFromBlock) {
public static int getTextureId(Block blockFromBlock, int metaFromBlock) {
for (int page = 0; page < Textures.BlockIcons.casingTexturePages.length; page++) {
ITexture[] casingTexturePage = Textures.BlockIcons.casingTexturePages[page];
if (casingTexturePage != null) {
for (int index = 0; index < casingTexturePage.length; index++) {
ITexture iTexture = casingTexturePage[index];
if (iTexture instanceof IBlockContainer) {
Block block = ((IBlockContainer) iTexture).getBlock();
byte meta = ((IBlockContainer) iTexture).getMeta();
int meta = ((IBlockContainer) iTexture).getMeta();
if (meta == metaFromBlock && blockFromBlock == block) {
return (page << 7) + index;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/common/GTProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ public void onBlockBreakingEvent(BlockEvent.BreakEvent event) {
if (stats == null) return;

TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
stats.onBreakBlock(player, event.x, event.y, event.z, event.block, (byte) event.blockMetadata, tile, event);
stats.onBreakBlock(player, event.x, event.y, event.z, event.block, event.blockMetadata, tile, event);
}

@SubscribeEvent
Expand All @@ -1574,7 +1574,7 @@ public void onBlockHarvestingEvent(BlockEvent.HarvestDropsEvent aEvent) {
aEvent.x,
aEvent.y,
aEvent.z,
(byte) aEvent.blockMetadata,
aEvent.blockMetadata,
aEvent.fortuneLevel,
aEvent.isSilkTouching,
aEvent);
Expand Down Expand Up @@ -2694,7 +2694,7 @@ public void onBlockBreakSpeedEvent(PlayerEvent.BreakSpeed aEvent) {
aEvent.x,
aEvent.y,
aEvent.z,
(byte) aEvent.metadata,
aEvent.metadata,
aEvent);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/common/items/MetaGeneratedItem01.java
Original file line number Diff line number Diff line change
Expand Up @@ -3481,7 +3481,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) {
OrePrefixes aPrefix = this.mGeneratedPrefixList[(aDamage / 1000)];
if ((aPrefix == OrePrefixes.dustImpure) || (aPrefix == OrePrefixes.dustPure)) {
Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ);
byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) {

aMaterial = cauldronRemap.getOrDefault(aMaterial, aMaterial);
Expand All @@ -3494,7 +3494,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) {
}
} else if (aPrefix == OrePrefixes.crushed) {
Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ);
byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) {
aItemEntity.setEntityItemStack(
GTOreDictUnificator
Expand All @@ -3504,7 +3504,7 @@ public boolean onEntityItemUpdate(EntityItem aItemEntity) {
}
} else if (aPrefix == OrePrefixes.dust && aMaterial == Materials.Wheat) {
Block tBlock = aItemEntity.worldObj.getBlock(tX, tY, tZ);
byte tMetaData = (byte) aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
int tMetaData = aItemEntity.worldObj.getBlockMetadata(tX, tY, tZ);
if ((tBlock == Blocks.cauldron) && (tMetaData > 0)) {
aItemEntity.setEntityItemStack(ItemList.Food_Dough.get(aItemEntity.getEntityItem().stackSize));
aItemEntity.worldObj.setBlockMetadataWithNotify(tX, tY, tZ, tMetaData - 1, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer
if (aBlock == null) {
return false;
}
byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ);
int aMeta = aWorld.getBlockMetadata(aX, aY, aZ);
if (aBlock == Blocks.rail) {
if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) {
aWorld.isRemote = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer
if (aBlock == null) {
return false;
}
byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ);
int aMeta = aWorld.getBlockMetadata(aX, aY, aZ);
if ((aBlock == Blocks.unpowered_repeater) || (aBlock == Blocks.powered_repeater)) {
if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) {
aWorld.setBlockMetadataWithNotify(aX, aY, aZ, aMeta / 4 * 4 + (aMeta % 4 + 1) % 4, 3);
Expand Down
Loading
Loading