-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Furnace Minecart Resupplying, add fuel cap to toggleable furnace …
…minecarts; Close #717
- Loading branch information
Showing
10 changed files
with
281 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/unascribed/fabrication/interfaces/ResupplyingFurnaceCart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.unascribed.fabrication.interfaces; | ||
|
||
import com.unascribed.fabrication.util.FurnaceResupplierFakeInventory; | ||
|
||
public interface ResupplyingFurnaceCart { | ||
FurnaceResupplierFakeInventory fabrication$getResupplyingFurnaceCart(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/unascribed/fabrication/interfaces/ToggleableFurnaceCart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.unascribed.fabrication.interfaces; | ||
|
||
public interface ToggleableFurnaceCart { | ||
int fabrication$tgfc$getPauseFuel(); | ||
void fabrication$tgfc$setFuel(int fuel); | ||
static int get(Object o) { | ||
return o instanceof ToggleableFurnaceCart ? ((ToggleableFurnaceCart) o).fabrication$tgfc$getPauseFuel() : 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...tion/mixin/d_minor_mechanics/furnace_minecart_resupplying/MixinFurnaceMinecartEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.unascribed.fabrication.mixin.d_minor_mechanics.furnace_minecart_resupplying; | ||
|
||
import com.unascribed.fabrication.FabConf; | ||
import com.unascribed.fabrication.interfaces.ResupplyingFurnaceCart; | ||
import com.unascribed.fabrication.interfaces.ToggleableFurnaceCart; | ||
import com.unascribed.fabrication.support.EligibleIf; | ||
import com.unascribed.fabrication.support.injection.FabInject; | ||
import com.unascribed.fabrication.util.FurnaceResupplierFakeInventory; | ||
import net.minecraft.block.entity.FurnaceBlockEntity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.vehicle.AbstractMinecartEntity; | ||
import net.minecraft.entity.vehicle.FurnaceMinecartEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
//TODO should just implement inventory if fabrication ever got a good way to create methods in classes | ||
@Mixin(FurnaceMinecartEntity.class) | ||
@EligibleIf(configAvailable="*.furnace_minecart_resupplying") | ||
public abstract class MixinFurnaceMinecartEntity extends AbstractMinecartEntity implements ResupplyingFurnaceCart { | ||
@Shadow | ||
public double pushX; | ||
@Shadow | ||
public double pushZ; | ||
@Shadow | ||
private int fuel; | ||
public FurnaceResupplierFakeInventory fabrication$hopperFuel = null; | ||
|
||
protected MixinFurnaceMinecartEntity(EntityType<?> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@FabInject(at=@At("HEAD"), method="tick()V") | ||
protected void tick(CallbackInfo ci) { | ||
if (!FabConf.isEnabled("*.furnace_minecart_resupplying")) return; | ||
if (fabrication$hopperFuel == null || fabrication$hopperFuel.isEmpty()) return; | ||
ItemStack fuelStack = fabrication$hopperFuel.stack; | ||
int fuel; | ||
int value = (FabConf.isEnabled("*.furnace_minecart_any_fuel") ? FurnaceBlockEntity.createFuelTimeMap().get(fuelStack.getItem())*2 : 3600) + ((fuel = ToggleableFurnaceCart.get(this)) == 0 ? this.fuel : fuel); | ||
if (value <= 32000) { | ||
fuelStack.decrement(1); | ||
if (this instanceof ToggleableFurnaceCart) ((ToggleableFurnaceCart) this).fabrication$tgfc$setFuel(value); | ||
else this.fuel = value; | ||
} | ||
if (ToggleableFurnaceCart.get(this) == 0 && this.fuel > 0) { | ||
Direction dir = this.getMovementDirection(); | ||
pushX = dir.getOffsetX(); | ||
pushZ = dir.getOffsetZ(); | ||
} | ||
} | ||
|
||
@Override | ||
public FurnaceResupplierFakeInventory fabrication$getResupplyingFurnaceCart() { | ||
if (fabrication$hopperFuel == null) return fabrication$hopperFuel = new FurnaceResupplierFakeInventory(this.world); | ||
return fabrication$hopperFuel; | ||
} | ||
|
||
/* I guess it's possible that someone inserts fuel and it doesn't turn into fuel before the cart gets unloaded, i think that's fine | ||
@FabInject(at=@At("TAIL"), method="writeCustomDataToNbt(Lnet/minecraft/nbt/NbtCompound;)V") | ||
protected void writeCustomDataToTag(NbtCompound nbt, CallbackInfo ci) { | ||
} | ||
@FabInject(at=@At("TAIL"), method="readCustomDataFromNbt(Lnet/minecraft/nbt/NbtCompound;)V") | ||
protected void readCustomDataFromTag(NbtCompound nbt, CallbackInfo ci) { | ||
} | ||
*/ | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...rication/mixin/d_minor_mechanics/furnace_minecart_resupplying/MixinHopperBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.unascribed.fabrication.mixin.d_minor_mechanics.furnace_minecart_resupplying; | ||
|
||
import com.unascribed.fabrication.FabConf; | ||
import com.unascribed.fabrication.interfaces.ResupplyingFurnaceCart; | ||
import com.unascribed.fabrication.support.EligibleIf; | ||
import com.unascribed.fabrication.support.injection.FabModifyArg; | ||
import com.unascribed.fabrication.support.injection.ModifyReturn; | ||
import net.minecraft.block.entity.HopperBlockEntity; | ||
import net.minecraft.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
@Mixin(HopperBlockEntity.class) | ||
@EligibleIf(configAvailable="*.furnace_minecart_resupplying") | ||
public class MixinHopperBlockEntity { | ||
|
||
@FabModifyArg(method="getInventoryAt(Lnet/minecraft/world/World;DDD)Lnet/minecraft/inventory/Inventory;", at=@At(value="INVOKE", target="Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;")) | ||
private static <T extends Entity> Predicate<T> addFurnaceCarts(Predicate<T> predicate) { | ||
if (!FabConf.isEnabled("*.furnace_minecart_resupplying")) return predicate; | ||
return predicate.or(new Predicate<>() { | ||
@Override | ||
public boolean test(T entity) { | ||
return entity instanceof ResupplyingFurnaceCart; | ||
} | ||
}); | ||
} | ||
@ModifyReturn(method="getInventoryAt(Lnet/minecraft/world/World;DDD)Lnet/minecraft/inventory/Inventory;", target="Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;") | ||
private static List<Entity> fabrication$changeFurnaceCarts(List<Entity> list) { | ||
for (int i=0, l=list.size(); i<l; i++) { | ||
Entity entity = list.get(i); | ||
if (entity instanceof ResupplyingFurnaceCart) { | ||
list.set(i, ((ResupplyingFurnaceCart) entity).fabrication$getResupplyingFurnaceCart()); | ||
} | ||
} | ||
return list; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/com/unascribed/fabrication/util/FurnaceResupplierFakeInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.unascribed.fabrication.util; | ||
|
||
import com.unascribed.fabrication.FabConf; | ||
import com.unascribed.fabrication.FabRefl; | ||
import net.minecraft.block.entity.FurnaceBlockEntity; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.vehicle.FurnaceMinecartEntity; | ||
import net.minecraft.inventory.SidedInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.network.Packet; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
|
||
public class FurnaceResupplierFakeInventory extends Entity implements SidedInventory { | ||
public ItemStack stack = ItemStack.EMPTY; | ||
public FurnaceResupplierFakeInventory(World world) { | ||
super(EntityType.EGG, world); | ||
} | ||
|
||
@Override | ||
protected void initDataTracker() { | ||
} | ||
|
||
@Override | ||
protected void readCustomDataFromNbt(NbtCompound nbt) { | ||
} | ||
|
||
@Override | ||
protected void writeCustomDataToNbt(NbtCompound nbt) { | ||
} | ||
|
||
@Override | ||
public Packet<?> createSpawnPacket() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return this.stack.isEmpty(); | ||
} | ||
|
||
@Override | ||
public ItemStack getStack(int slot) { | ||
if (slot != 0) return ItemStack.EMPTY; | ||
return this.stack; | ||
} | ||
|
||
@Override | ||
public ItemStack removeStack(int slot, int amount) { | ||
if (slot != 0) return ItemStack.EMPTY; | ||
return this.stack.split(amount); | ||
} | ||
|
||
@Override | ||
public ItemStack removeStack(int slot) { | ||
if (slot != 0) return ItemStack.EMPTY; | ||
ItemStack ret = this.stack; | ||
this.stack = ItemStack.EMPTY; | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void setStack(int slot, ItemStack stack) { | ||
if (slot != 0) return; | ||
this.stack = stack; | ||
} | ||
|
||
@Override | ||
public void markDirty() { | ||
} | ||
|
||
@Override | ||
public boolean canPlayerUse(PlayerEntity player) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
this.stack = ItemStack.EMPTY; | ||
} | ||
public int getMaxCountPerStack() { | ||
return 1; | ||
} | ||
|
||
public static int[] SLOTS = new int[]{0}; | ||
@Override | ||
public int[] getAvailableSlots(Direction side) { | ||
return SLOTS; | ||
} | ||
|
||
@Override | ||
public boolean canInsert(int slot, ItemStack stack, Direction dir) { | ||
if (!FabConf.isEnabled("*.furnace_minecart_resupplying")) return false; | ||
if (slot != 0 || !this.stack.isEmpty()) return false; | ||
if (FabConf.isEnabled("*.furnace_minecart_any_fuel")) return FurnaceBlockEntity.canUseAsFuel(stack); | ||
return FabRefl.getAcceltableFuel().test(stack); | ||
} | ||
|
||
@Override | ||
public boolean canExtract(int slot, ItemStack stack, Direction dir) { | ||
return false; | ||
} | ||
} |