Preserve drink containers and include reviewed Arrakis terrain prevention
This commit is contained in:
parent
3322ba507e
commit
f4f7e34902
5 changed files with 33 additions and 9 deletions
|
|
@ -41,7 +41,7 @@ final class RegionalCraftRemainders {
|
|||
toNative=item.getMethod("asNMSCopy",ItemStack.class);
|
||||
}
|
||||
|
||||
void install(NamespacedKey name) throws ReflectiveOperationException {
|
||||
void install(NamespacedKey name, ItemStack result) throws ReflectiveOperationException {
|
||||
Object key=keyOf.invoke(null,recipeRegistry,name);
|
||||
Object originalHolder=((Optional<?>)lookup.invoke(manager,key)).orElseThrow();
|
||||
Object original=valueOf.invoke(originalHolder);
|
||||
|
|
@ -53,10 +53,23 @@ final class RegionalCraftRemainders {
|
|||
@SuppressWarnings("unchecked") List<Object> remainder=(List<Object>)outcome;
|
||||
Object input=args[0];
|
||||
int slots=(Integer)size.invoke(input);
|
||||
int reusedBottles=filledGlass(result.getType())?result.getAmount():0;
|
||||
var sources=new Material[slots];
|
||||
for(int i=0;i<slots;i++){
|
||||
if(!((ItemStack)toBukkit.invoke(null,remainder.get(i))).isEmpty())continue;
|
||||
var source=(ItemStack)toBukkit.invoke(null,stackAt.invoke(input,i));
|
||||
Material container=container(source.getType());
|
||||
sources[i]=source.getType();
|
||||
if(sources[i]==Material.GLASS_BOTTLE&&reusedBottles>0)reusedBottles--;
|
||||
}
|
||||
for(int i=0;i<slots;i++){
|
||||
var nativeRemainder=(ItemStack)toBukkit.invoke(null,remainder.get(i));
|
||||
if(reusedBottles>0&&filledGlass(sources[i])
|
||||
&&(nativeRemainder.isEmpty()||nativeRemainder.getType()==Material.GLASS_BOTTLE)){
|
||||
remainder.set(i,toNative.invoke(null,new ItemStack(Material.AIR)));
|
||||
reusedBottles--;
|
||||
continue;
|
||||
}
|
||||
if(!nativeRemainder.isEmpty())continue;
|
||||
Material container=container(sources[i]);
|
||||
if(container!=null)remainder.set(i,toNative.invoke(null,new ItemStack(container)));
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +84,10 @@ final class RegionalCraftRemainders {
|
|||
}
|
||||
}
|
||||
|
||||
static boolean filledGlass(Material material) {
|
||||
return material==Material.POTION||material==Material.HONEY_BOTTLE;
|
||||
}
|
||||
|
||||
static Material container(Material input) {
|
||||
return switch(input){
|
||||
case POTION->Material.GLASS_BOTTLE;
|
||||
|
|
|
|||
|
|
@ -66,9 +66,10 @@ final class RegionalFoodStations implements Listener {
|
|||
if (productions.putIfAbsent(row.key(),row)!=null || Bukkit.getRecipe(row.key())!=null)
|
||||
throw new IllegalStateException("Duplicate regional recipe "+row.key());
|
||||
if (!Bukkit.addRecipe(recipe(row))) throw new IllegalStateException("Could not register "+row.key());
|
||||
if(row.station()==Station.CRAFTING && row.ingredients().stream().anyMatch(ingredient->RegionalCraftRemainders.container(ingredient.choice().getItemStack().getType())!=null)){
|
||||
if(row.station()==Station.CRAFTING && (RegionalCraftRemainders.filledGlass(row.result().getType())
|
||||
||row.ingredients().stream().anyMatch(ingredient->RegionalCraftRemainders.container(ingredient.choice().getItemStack().getType())!=null))){
|
||||
if(remainders==null)remainders=new RegionalCraftRemainders();
|
||||
remainders.install(row.key());
|
||||
remainders.install(row.key(),row.result());
|
||||
}
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this,plugin);
|
||||
|
|
|
|||
|
|
@ -1050,6 +1050,10 @@
|
|||
"id": "minecraft:sugar",
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:glass_bottle",
|
||||
"amount": 1
|
||||
},
|
||||
{
|
||||
"id": "minecraft:sweet_berries",
|
||||
"amount": 1
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ class RegionalCookingMerge implements Opcodes {
|
|||
else if(args[2].endsWith("kaitain.class"))addLivestock(old);
|
||||
else throw new IllegalArgumentException("Unknown PlanetMobs profile");
|
||||
}
|
||||
case TERRAIN+"DuneTerrain$PlanetChunkGenerator" -> copy(old,donor,"placeOasisTree");
|
||||
case TERRAIN+"DuneTerrain$PlanetChunkGenerator" -> copy(old,donor,
|
||||
"placeOasisTree","generateNoise","placeSpiceDeposits","placeRandomSpicePatch");
|
||||
case TERRAIN+"SpiceDepositProvenance" -> copy(old,donor,"capture","populate","hostSand");
|
||||
default -> throw new IllegalArgumentException("Unexpected target "+old.name);
|
||||
}
|
||||
var writer=new ClassWriter(reader,0);
|
||||
|
|
@ -84,7 +86,7 @@ class RegionalCookingMerge implements Opcodes {
|
|||
for (String name : names) {
|
||||
var method = unique(donor, name);
|
||||
var prior = old.methods.stream().filter(m -> m.name.equals(name) && m.desc.equals(method.desc)).findFirst();
|
||||
if (prior.isEmpty() && !Set.of("hydrationRestoration", "regionalCookbook", "regionalRecipe", "applyRegionalIcon").contains(name)) {
|
||||
if (prior.isEmpty() && !Set.of("hydrationRestoration", "regionalCookbook", "regionalRecipe", "applyRegionalIcon", "hostSand").contains(name)) {
|
||||
throw new IllegalArgumentException("Missing retained method " + name);
|
||||
}
|
||||
prior.ifPresent(old.methods::remove);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ ROLES = {
|
|||
JARVIS + "RegionalFoodAcquisition", JARVIS + "RegionalFoodItem",
|
||||
JARVIS + "RegionalFoodStations", JARVIS + "NativeLeafDecay"), (CATALOG,)),
|
||||
"gui": ((GUI + "OrganisationMenus",), (GUI + "RegionalCookbook",), (CATALOG,)),
|
||||
"arrakis": ((TERRAIN + "DuneTerrain$PlanetChunkGenerator",), (), ()),
|
||||
"arrakis": ((TERRAIN + "DuneTerrain$PlanetChunkGenerator", TERRAIN + "SpiceDepositProvenance"), (), ()),
|
||||
"giedi": ((TERRAIN + "PlanetMobs", TERRAIN + "NativePlants"), (), ()),
|
||||
"kaitain": ((TERRAIN + "PlanetMobs",), (TERRAIN + "KaitainLivestock",), ()),
|
||||
}
|
||||
|
|
@ -65,4 +65,4 @@ if __name__ == "__main__":
|
|||
parser.add_argument("donor_sha")
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("classpath")
|
||||
assemble(**vars(parser.parse_args()))
|
||||
assemble(**vars(parser.parse_args()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff