mirror of
https://github.com/GTNewHorizons/BetterBuildersWands.git
synced 2026-10-25 20:22:27 +00:00
Custom mapping stacksize improvements (#25)
Co-authored-by: Guillaume Mercier <17766417+C0bra5@users.noreply.github.com>
This commit is contained in:
1 parent
62f055b17c
commit
a39985b489
8 files changed
+80
-22
No files matched your search
+3
-2
@@ -10,6 +10,7 @@ import gcewing.architecture.common.tile.TileShape;
|
||||
import portablejim.bbw.BetterBuildersWandsMod;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.core.conversion.CustomMapping;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
public class ArchitectureCraftCustomMapping extends CustomMapping {
|
||||
@@ -22,7 +23,7 @@ public class ArchitectureCraftCustomMapping extends CustomMapping {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItems(IWorldShim world, Point3d point) {
|
||||
public ItemStack getItems(IWorldShim world, IPlayerShim player, Point3d point) {
|
||||
TileEntity tileEntity = world.getTile(point);
|
||||
if (tileEntity instanceof TileShape) {
|
||||
TileShape shapeTile = ((TileShape) tileEntity);
|
||||
@@ -30,7 +31,7 @@ public class ArchitectureCraftCustomMapping extends CustomMapping {
|
||||
itemStack.setItemDamage(getMeta());
|
||||
return itemStack;
|
||||
}
|
||||
return super.getItems(world, point);
|
||||
return super.getItems(world, player, point);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
||||
@@ -12,6 +12,7 @@ import forestry.plugins.PluginManager;
|
||||
import portablejim.bbw.BetterBuildersWandsMod;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.core.conversion.CustomMapping;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
public class ForestryMCCustomMapping extends CustomMapping {
|
||||
@@ -21,12 +22,12 @@ public class ForestryMCCustomMapping extends CustomMapping {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItems(IWorldShim world, Point3d point) {
|
||||
public ItemStack getItems(IWorldShim world, IPlayerShim player, Point3d point) {
|
||||
TileEntity tileEntity = world.getTile(point);
|
||||
if (tileEntity instanceof TileWood) {
|
||||
return TileWood.getPickBlock(getLookBlock(), world.getWorld(), point.x, point.y, point.z);
|
||||
}
|
||||
return super.getItems(world, point);
|
||||
return super.getItems(world, player, point);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import portablejim.bbw.BetterBuildersWandsMod;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.compat.ztones.Ztones;
|
||||
import portablejim.bbw.core.conversion.CustomMapping;
|
||||
import portablejim.bbw.core.conversion.ICustomMapping;
|
||||
import portablejim.bbw.core.items.IWandItem;
|
||||
import portablejim.bbw.core.wands.IWand;
|
||||
import portablejim.bbw.shims.BasicPlayerShim;
|
||||
@@ -58,7 +58,7 @@ public class BlockEvents {
|
||||
if (sourceItems != null && sourceItems.getItem() instanceof ItemBlock) {
|
||||
Block targetedBlock = worldShim.getBlock(clickedPos);
|
||||
int meta = worldShim.getMetadata(clickedPos);
|
||||
CustomMapping customMapping = BetterBuildersWandsMod.instance.mappingManager
|
||||
ICustomMapping customMapping = BetterBuildersWandsMod.instance.mappingManager
|
||||
.getMapping(targetedBlock, meta);
|
||||
|
||||
int numBlocks;
|
||||
|
||||
@@ -23,7 +23,7 @@ import portablejim.bbw.BetterBuildersWandsMod;
|
||||
import portablejim.bbw.basics.EnumFluidLock;
|
||||
import portablejim.bbw.basics.EnumLock;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.core.conversion.CustomMapping;
|
||||
import portablejim.bbw.core.conversion.ICustomMapping;
|
||||
import portablejim.bbw.core.wands.IWand;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
@@ -66,9 +66,9 @@ public class WandWorker {
|
||||
}
|
||||
|
||||
if (!usedBackhand) {
|
||||
CustomMapping customMapping = BetterBuildersWandsMod.instance.mappingManager.getMapping(block, meta);
|
||||
ICustomMapping customMapping = BetterBuildersWandsMod.instance.mappingManager.getMapping(block, meta);
|
||||
if (customMapping != null) {
|
||||
return customMapping.getItems(world, blockPos);
|
||||
return customMapping.getItems(world, player, blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,13 +298,15 @@ public class WandWorker {
|
||||
|
||||
Block targetBlock = Block.getBlockFromItem(needItem.getItem());
|
||||
int targetMeta = needItem.getItemDamage();
|
||||
CustomMapping mapping = BetterBuildersWandsMod.instance.mappingManager.getMapping(targetBlock, targetMeta);
|
||||
ICustomMapping mapping = BetterBuildersWandsMod.instance.mappingManager.getMapping(targetBlock, targetMeta);
|
||||
boolean isNBTSensitive = mapping != null && mapping.shouldCopyTileNBT();
|
||||
|
||||
boolean isCreative = playerShim.isCreative();
|
||||
Point3d[] blockPoss = blockPosList.toArray(new Point3d[0]);
|
||||
needItem.stackSize = blockPoss.length;
|
||||
int takeFromInventory = playerShim.useItem(needItem, isNBTSensitive);;
|
||||
// stack size shouldn't be below zero but better safe than sorry.
|
||||
int amountToConsume = Math.max(1, sourceItems.stackSize);
|
||||
needItem.stackSize = blockPoss.length * amountToConsume;
|
||||
int takeFromInventory = playerShim.useItem(needItem, isNBTSensitive) / amountToConsume;
|
||||
|
||||
for (int i = 0; i < takeFromInventory; ++i) {
|
||||
Point3d blockPos = blockPoss[i];
|
||||
|
||||
@@ -4,12 +4,13 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
/**
|
||||
* Created by james on 18/12/15.
|
||||
*/
|
||||
public class CustomMapping {
|
||||
public class CustomMapping implements ICustomMapping {
|
||||
|
||||
private final Block lookBlock;
|
||||
private final int meta;
|
||||
@@ -45,7 +46,7 @@ public class CustomMapping {
|
||||
return items;
|
||||
}
|
||||
|
||||
public ItemStack getItems(IWorldShim world, Point3d point) {
|
||||
public ItemStack getItems(IWorldShim world, IPlayerShim player, Point3d point) {
|
||||
return getItems();
|
||||
}
|
||||
|
||||
@@ -61,6 +62,11 @@ public class CustomMapping {
|
||||
return shouldCopyTileNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
return this == that || (that instanceof CustomMapping && this.equals((CustomMapping) that));
|
||||
}
|
||||
|
||||
public boolean equals(CustomMapping that) {
|
||||
return this.lookBlock == that.lookBlock && this.meta == that.meta
|
||||
&& this.items == that.items
|
||||
@@ -68,4 +74,15 @@ public class CustomMapping {
|
||||
&& this.placeMeta == that.placeMeta
|
||||
&& this.shouldCopyTileNBT == that.shouldCopyTileNBT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = lookBlock.hashCode();
|
||||
result = 31 * result + meta;
|
||||
result = 31 * result + items.hashCode();
|
||||
result = 31 * result + placeBlock.hashCode();
|
||||
result = 31 * result + placeMeta;
|
||||
result = 31 * result + Boolean.hashCode(shouldCopyTileNBT);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import portablejim.bbw.BetterBuildersWandsMod;
|
||||
*/
|
||||
public class CustomMappingManager {
|
||||
|
||||
ArrayList<CustomMapping> mappings;
|
||||
ArrayList<ICustomMapping> mappings;
|
||||
|
||||
public CustomMappingManager() {
|
||||
mappings = new ArrayList<>();
|
||||
@@ -68,8 +68,8 @@ public class CustomMappingManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CustomMapping getMapping(Block block, int meta) {
|
||||
for (CustomMapping mapping : mappings) {
|
||||
public ICustomMapping getMapping(Block block, int meta) {
|
||||
for (ICustomMapping mapping : mappings) {
|
||||
if (mapping.getLookBlock() == block && mapping.getMeta() == meta) {
|
||||
return mapping;
|
||||
}
|
||||
@@ -77,9 +77,9 @@ public class CustomMappingManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setMapping(CustomMapping newMapping) {
|
||||
public void setMapping(ICustomMapping newMapping) {
|
||||
for (int i = 0; i < mappings.size(); i++) {
|
||||
CustomMapping current = mappings.get(i);
|
||||
ICustomMapping current = mappings.get(i);
|
||||
if (current.getLookBlock() == newMapping.getLookBlock() && current.getMeta() == newMapping.getMeta()) {
|
||||
if (current.equals(newMapping)) {
|
||||
// Already there
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package portablejim.bbw.core.conversion;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
public interface ICustomMapping {
|
||||
|
||||
/**
|
||||
* @return The block being looked at.
|
||||
*/
|
||||
Block getLookBlock();
|
||||
|
||||
/**
|
||||
* @return The meta of the block being looked at.
|
||||
*/
|
||||
int getMeta();
|
||||
|
||||
/**
|
||||
* Gets the item that should be placed.
|
||||
*
|
||||
* @param world The world where the block will be placed.
|
||||
* @param player The player placing the blocks.
|
||||
* @param point The position where the player is looking.
|
||||
* @return An item stack representing a single block being placed.
|
||||
*/
|
||||
ItemStack getItems(IWorldShim world, IPlayerShim player, Point3d point);
|
||||
|
||||
/**
|
||||
* @return True to copy the nbt data of the tile entity of the original block.
|
||||
*/
|
||||
boolean shouldCopyTileNBT();
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.compat.ztones.Ztones;
|
||||
import portablejim.bbw.core.WandWorker;
|
||||
import portablejim.bbw.core.conversion.CustomMapping;
|
||||
import portablejim.bbw.core.conversion.ICustomMapping;
|
||||
import portablejim.bbw.core.wands.IWand;
|
||||
import portablejim.bbw.shims.BasicPlayerShim;
|
||||
import portablejim.bbw.shims.BasicWorldShim;
|
||||
@@ -75,7 +76,7 @@ public abstract class ItemBasicWand extends Item implements IWandItem {
|
||||
ItemStack sourceItems = worker.getProperItemStack(worldShim, playerShim, clickedPos);
|
||||
|
||||
if (sourceItems != null && sourceItems.getItem() instanceof ItemBlock) {
|
||||
CustomMapping customMapping = getCustomMapping(worldShim, playerShim, clickedPos);
|
||||
ICustomMapping customMapping = getCustomMapping(worldShim, playerShim, clickedPos);
|
||||
|
||||
int numBlocks;
|
||||
|
||||
@@ -199,7 +200,7 @@ public abstract class ItemBasicWand extends Item implements IWandItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static CustomMapping getCustomMapping(IWorldShim worldShim, IPlayerShim playerShim, Point3d clickedPos) {
|
||||
public static ICustomMapping getCustomMapping(IWorldShim worldShim, IPlayerShim playerShim, Point3d clickedPos) {
|
||||
if (Loader.isModLoaded("backhand")) {
|
||||
ItemStack backhandItem = WandWorker.getProperItemStackBackhand(playerShim);
|
||||
|
||||
@@ -207,7 +208,7 @@ public abstract class ItemBasicWand extends Item implements IWandItem {
|
||||
Block offhandBlock = ((ItemBlock) backhandItem.getItem()).field_150939_a;
|
||||
int meta = backhandItem.getItemDamage();
|
||||
|
||||
CustomMapping existing = BetterBuildersWandsMod.instance.mappingManager.getMapping(offhandBlock, meta);
|
||||
ICustomMapping existing = BetterBuildersWandsMod.instance.mappingManager.getMapping(offhandBlock, meta);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user