Skip to content

Commit

Permalink
add reinforced gear box and better gear tiering
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerahuntley committed Jul 9, 2023
1 parent 62d3e75 commit 93c6a4d
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 43 deletions.
Binary file added .github/images/regular_gearbox_vs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/reinforced_gearbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/reinforced_gearbox_vs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ built using [bta-example-mod](https://github.com/Turnip-Labs/bta-example-mod/)

Gear Item: This item is used for crafting other items.

Gearboxes: These blocks are activated with bones and activate adjacent blocks. They occasionally break a bone in your hand - based on the number of adjacent blocks. Each Gearbox can only touch one gear block directly at a time, but some gear blocks can be chained.
Gearboxes: These blocks are activated with bones and activate adjacent blocks. They occasionally break a bone in your hand - based on the number of adjacent blocks.

![Gearbox in use](.github/images/gearbox_in_use.png)

Each Gearbox can only touch one gear block directly at a time and power one adjacent block. If you want to power multiple blocks, you can use a Reinforced Gearbox, which can power many blocks at once (at the cost of additional bones).

![Gearbox powers 1 machine](.github/images/regular_gearbox_vs.png)
![Reinforced Gearbox powers multiple machines](.github/images/reinforced_gearbox_vs.png)

Gear Trommel: This block sits underneath a trommel, and if there are items to seive, this block will activate the trommel without the need for coal.

Chest Sorter: This powered block is capable of sorting attached chests. It can be linked in a row and requires the first Chest Sorter to have a chest placed on top. It is crafted using 4 gearboxes, 4 clay, and one chest, similar to TNT.
Expand All @@ -22,6 +27,7 @@ Chest Sorter: This powered block is capable of sorting attached chests. It can b

![Gear](.github/images/gear.png)
![Gearbox](.github/images/gearbox.png)
![Reinforced Gearbox](.github/images/reinforced_gearbox.png)
![Trommel Gearbox](.github/images/trommelgearbox.png)
![Chest Sorter](.github/images/chestsorter.png)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ loader_version=0.14.19-babric.1
halplibe_version=1.1.4

# Mod
mod_version=1.0.2
mod_version=1.1.0
mod_group=youngsditch
mod_name=ancientlogistics
12 changes: 12 additions & 0 deletions src/main/java/youngsditch/ancientlogistics/AncientLogistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public class AncientLogistics implements ModInitializer {
put("gearboxID", "900");
put("geartrommelID", "901");
put("gearchestID", "902");
put("reinforcedgearboxID", "903");
// More keys and values...
}});

public static final Item gear = ItemHelper.createItem(MOD_ID, new Item(config.getInt("gearID")), "gear", "gear.png");
public static final Block gearBlock = BlockHelper.createBlock(MOD_ID, new GearBox(config.getInt("gearboxID")), "gearbox", "gear_top.png", "gear_block.png", Block.soundMetalFootstep, 0.1f, 0.1f, 0.0f);
public static final Block reinforcedGearBlock = BlockHelper.createBlock(MOD_ID, new ReinforcedGearBox(config.getInt("reinforcedgearboxID")), "reinforcedgearbox", "gear_top.png", "reinf_gear_block.png", Block.soundMetalFootstep, 0.1f, 0.1f, 0.0f);
public static final Block gearTrommelBlock = BlockHelper.createBlock(MOD_ID, new GearTrommel(config.getInt("geartrommelID")), "geartrommel", "gear_top.png", "gear_trommel.png", Block.soundMetalFootstep, 0.1f, 0.1f, 0.0f);
public static final Block gearChestBlock = BlockHelper.createBlock(MOD_ID, new GearChestSorter(config.getInt("gearchestID")), "gearchest", "gear_top.png", "gear_chest.png", Block.soundWoodFootstep, 0.1f, 0.1f, 0.0f);

Expand All @@ -38,6 +40,16 @@ public void onInitialize() {
'I', Item.ingotIron
});

// crafting recipe for reinforced gearbox
RecipeHelper.Crafting.createRecipe(reinforcedGearBlock, 1, new Object[]{
"CGC",
"GIG",
"CGC",
'G', gearBlock,
'C', Item.nethercoal,
'I', Item.ingotIron
});

// crafting recipe for gear trommel
RecipeHelper.Crafting.createRecipe(gearTrommelBlock, 1, new Object[]{
"CGC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Comparator;

import net.minecraft.src.*;
import youngsditch.ancientlogistics.AncientLogistics;
import youngsditch.ancientlogistics.mixin.ChestAccessor;

public class GearChestSorter extends GearUsable {
Expand All @@ -24,45 +25,57 @@ class ChestWithDistance {
}

@Override
public int costToUse(World world, int x, int y, int z, EntityPlayer player) {
public int costToUse(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {

// get block above
Block blockAbove = Block.blocksList[world.getBlockId(x, y + 1, z)];

if (blockAbove instanceof BlockChest) {
// first block must have a chest over it, the rest don't matter
if(!canConnect) {
return 2;
} else {

GearInfo<GearChestSorter>[] gearInfo = getConnected(world, x, y, z, GearChestSorter.class);
// get all connected gears
GearInfo<GearChestSorter>[] gearInfo = getConnected(world, x, y, z, GearChestSorter.class);

int chests = 0;
int chests = 0;

// check above each gear for a chest
for (int i = 0; i < gearInfo.length; i++) {
int[] coordinates = gearInfo[i].getCoordinates();
int[] chestCoordinates = {coordinates[0], coordinates[1] + 1, coordinates[2]};
if (Block.blocksList[world.getBlockId(chestCoordinates[0], chestCoordinates[1], chestCoordinates[2])] instanceof BlockChest) {
chests++;
// check above each gear for a chest
for (int i = 0; i < gearInfo.length; i++) {
int[] coordinates = gearInfo[i].getCoordinates();
int[] chestCoordinates = {coordinates[0], coordinates[1] + 1, coordinates[2]};
if (Block.blocksList[world.getBlockId(chestCoordinates[0], chestCoordinates[1], chestCoordinates[2])] instanceof BlockChest) {
chests++;
}
}
}

// return check count * 2
return chests * 2;

} else {
// return 0 if no chest above
return 0;
// return check count * 2
return chests * 2;
}
}

// return 0 if no chest above
return 0;
}

@Override
public int onGearUsed(World world, int x, int y, int z, EntityPlayer player) {
public int onGearUsed(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {
// get block above
Block blockAbove = Block.blocksList[world.getBlockId(x, y + 1, z)];

if (blockAbove instanceof BlockChest) {
// first block must have a chest over it, the rest don't matter

GearInfo<GearChestSorter>[] gearInfo = getConnected(world, x, y, z, GearChestSorter.class);
GearInfo<GearChestSorter>[] gearInfo;

if(canConnect) {
gearInfo = getConnected(world, x, y, z, GearChestSorter.class);
} else {
gearInfo = getSolo(world, x, y, z, GearChestSorter.class);
}

AncientLogistics.LOGGER.info("Found " + gearInfo.length + " connected gears");

ChestWithDistance[] chests = new ChestWithDistance[gearInfo.length];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class GearGenerator extends GearBlock {
private Random rand = new Random();
protected boolean canRunMultiple = false;

public GearGenerator(int id) {
super(id);
Expand Down Expand Up @@ -113,7 +114,11 @@ public boolean blockActivated(World world, int x, int y, int z, EntityPlayer pla
int[] coords = gearUsable.getCoordinates();

// check if the user has enough bones, roughly
int bonesNeeded = gearUsable.getGear().costToUse(world, coords[0], coords[1], coords[2], player);
int bonesNeeded = gearUsable.getGear().costToUse(world, coords[0], coords[1], coords[2], player, this.canRunMultiple);

if(!player.getGamemode().consumeBlocks) {
bonesNeeded = 1; // still needs one in hand
}

// bones ends up being somewhat random, but we're gonna say 1/10 of the value is the cost
// if theres even a val of 1, which might be free, the cost ceil goes up to 1
Expand All @@ -124,15 +129,17 @@ public boolean blockActivated(World world, int x, int y, int z, EntityPlayer pla
}

// spawn particles
int value = gearUsable.getGear().onGearUsed(world, coords[0], coords[1], coords[2], player);
int value = gearUsable.getGear().onGearUsed(world, coords[0], coords[1], coords[2], player, this.canRunMultiple);

showWorking(world, x, y, z, player);
// 1 in 10 chance of breaking a bone for every value
for (int i = 0; i < value; i++) {
if (this.rand.nextInt(10) == 0) {
// log break
player.worldObj.playSoundAtEntity(player, "mob.skeletonhurt", 0.5f, 1.0f);
player.getCurrentEquippedItem().consumeItem(player);
if(playerHasBone(player) && player.getCurrentEquippedItem().stackSize > 0) {
player.getCurrentEquippedItem().consumeItem(player);
}
}
}
} else {
Expand Down
83 changes: 65 additions & 18 deletions src/main/java/youngsditch/ancientlogistics/gears/GearTrommel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,94 @@ public boolean findNextToSieve(TileEntityTrommel tileEntityTrommel) {
}

@Override
public int costToUse(World world, int x, int y, int z, EntityPlayer player) {
public int costToUse(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {

// get block above
Block blockAbove = Block.blocksList[world.getBlockId(x, y + 1, z)];

// if block above is a trommel
if (blockAbove instanceof BlockTrommel) {
TileEntityTrommel tileEntityTrommel = (TileEntityTrommel)world.getBlockTileEntity(x, y + 1, z);
if (blockAbove instanceof BlockTrommel){

if(!canConnect) {
TileEntityTrommel tileEntityTrommel = (TileEntityTrommel)world.getBlockTileEntity(x, y + 1, z);

// if trommel is not burning and there is something to burn
if(findNextToSieve(tileEntityTrommel) && tileEntityTrommel.burnTime < 50) {
return 2;
}
} else {
GearInfo<GearTrommel>[] gearInfo = getConnected(world, x, y, z, GearTrommel.class);

// if trommel is not burning and there is something to burn
if(findNextToSieve(tileEntityTrommel) && tileEntityTrommel.burnTime < 50) {
return 2;
int trommels = 0;

// check above each gear for a trommel
for (int i = 0; i < gearInfo.length; i++) {
int[] coordinates = gearInfo[i].getCoordinates();
int[] trommelCoordinates = {coordinates[0], coordinates[1] + 1, coordinates[2]};
if (Block.blocksList[world.getBlockId(trommelCoordinates[0], trommelCoordinates[1], trommelCoordinates[2])] instanceof BlockTrommel) {
trommels++;
}
}

// return check count * 2
return trommels * 2;
}
}

return 0;
}

private boolean powerTrommel(World world, int x, int y, int z) {
TileEntityTrommel tileEntityTrommel = (TileEntityTrommel)world.getBlockTileEntity(x, y, z);

// store burning state before adding burn time
boolean isBurning = tileEntityTrommel.isBurning();

// if trommel is not burning and there is something to burn
if(findNextToSieve(tileEntityTrommel) && tileEntityTrommel.burnTime < 50) {
tileEntityTrommel.burnTime = Math.min(tileEntityTrommel.burnTime + 25, 50);

// if burning has changed, update block state and notify
if(isBurning != tileEntityTrommel.isBurning()) {
BlockTrommel.updateTrommelBlockState(tileEntityTrommel.burnTime > 0, world, x, y, z);
tileEntityTrommel.onInventoryChanged();
}
return true;
}
return false;
}

@Override
public int onGearUsed(World world, int x, int y, int z, EntityPlayer player) {
public int onGearUsed(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {
// get block above
Block blockAbove = Block.blocksList[world.getBlockId(x, y + 1, z)];

// if block above is a trommel
if (blockAbove instanceof BlockTrommel) {
TileEntityTrommel tileEntityTrommel = (TileEntityTrommel)world.getBlockTileEntity(x, y + 1, z);

// store burning state before adding burn time
boolean isBurning = tileEntityTrommel.isBurning();
// get all connected gears
GearInfo<GearTrommel>[] gearInfo;

if(canConnect) {
gearInfo = getConnected(world, x, y, z, GearTrommel.class);
} else {
gearInfo = getSolo(world, x, y, z, GearTrommel.class);
}

// if trommel is not burning and there is something to burn
if(findNextToSieve(tileEntityTrommel) && tileEntityTrommel.burnTime < 50) {
tileEntityTrommel.burnTime = Math.min(tileEntityTrommel.burnTime + 25, 50);
int totalCost = 0;

// if burning has changed, update block state and notify
if(isBurning != tileEntityTrommel.isBurning()) {
BlockTrommel.updateTrommelBlockState(tileEntityTrommel.burnTime > 0, world, x, y + 1, z);
tileEntityTrommel.onInventoryChanged();
// check above each gear for a trommel
for (int i = 0; i < gearInfo.length; i++) {
int[] coordinates = gearInfo[i].getCoordinates();
int[] trommelCoordinates = {coordinates[0], coordinates[1] + 1, coordinates[2]};
if (Block.blocksList[world.getBlockId(trommelCoordinates[0], trommelCoordinates[1], trommelCoordinates[2])] instanceof BlockTrommel) {
if(powerTrommel(world, trommelCoordinates[0], trommelCoordinates[1], trommelCoordinates[2])){
totalCost++;
}
}
return 2;
}

return totalCost * 2;
}

return 0;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/youngsditch/ancientlogistics/gears/GearUsable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ public GearUsable(int id) {
super(id);
}

public int onGearUsed(World world, int x, int y, int z, EntityPlayer player) {
public int onGearUsed(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {
return 0;
}

public int costToUse(World world, int x, int y, int z, EntityPlayer player) {
public int costToUse(World world, int x, int y, int z, EntityPlayer player, boolean canConnect) {
return 0;
}

@SuppressWarnings("unchecked")
public <T extends GearBlock> GearInfo<T>[] getSolo(World world, int x, int y, int z, Class<T> blockType) {
ArrayList<GearInfo<T>> connected = new ArrayList<>();
connected.add(new GearInfo<T>(new int[]{x, y, z}, 0, blockType.cast(this)));

return connected.toArray(new GearInfo[connected.size()]);
}

@SuppressWarnings("unchecked")
public <T extends GearBlock> GearInfo<T>[] getConnected(World world, int x, int y, int z, Class<T> blockType) {
ArrayList<GearInfo<T>> connected = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package youngsditch.ancientlogistics.gears;

public class ReinforcedGearBox extends GearBox {

public ReinforcedGearBox(int id) {
super(id);
this.canRunMultiple = true;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/resources/lang/ancientlogistics/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ item.ancientlogistics.gear.desc=It's a gear.

tile.ancientlogistics.gearbox.name=Gearbox
tile.ancientlogistics.gearbox.desc=It's a gearbox.
tile.ancientlogistics.reinforcedgearbox.name=Reinforced Gearbox
tile.ancientlogistics.reinforcedgearbox.desc=It's a reinforced gearbox.
tile.ancientlogistics.geartrommel.name=Trommel Gearbox
tile.ancientlogistics.geartrommel.desc=It's a trommel gearbox.
tile.ancientlogistics.gearchest.name=Chest Sorter
Expand Down

0 comments on commit 93c6a4d

Please sign in to comment.