MCRandomizer bugfixes (and debug info)

master
sigonasr2 6 years ago
parent e8de1218db
commit 20a4f905a1
  1. 2
      MCRandomizer/src/scramble/plugin/FurnaceRecipeStore.java
  2. 3
      MCRandomizer/src/scramble/plugin/ShapedRecipeStore.java
  3. 3
      MCRandomizer/src/scramble/plugin/ShapelessRecipeStore.java
  4. 9
      MCRandomizer/src/scramble/plugin/Template.java
  5. 46
      MCRandomizer/src/scramble/plugin/listener/ExampleListener.java

@ -17,7 +17,7 @@ public class FurnaceRecipeStore implements RecipeStore{
@Override
public void createRecipe() {
FurnaceRecipe rec = new FurnaceRecipe(new NamespacedKey(Template.plugin,"furnace"+System.nanoTime()),new ItemStack(Material.getMaterial(finalItem)),new RecipeChoice.MaterialChoice(craftingitems),
FurnaceRecipe rec = new FurnaceRecipe(new NamespacedKey(Template.plugin,"furnace"+(Template.recipe_count++)),new ItemStack(Material.getMaterial(finalItem)),new RecipeChoice.MaterialChoice(craftingitems),
Template.r.nextInt(100)+1f,Template.r.nextInt(81)+20);
Bukkit.getLogger().info("Added recipe for "+finalItem);
Bukkit.getLogger().info("Furnace recipe w/");

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.RecipeChoice.MaterialChoice;
@ -24,7 +25,7 @@ public class ShapedRecipeStore implements RecipeStore{
@Override
public void createRecipe() {
ShapedRecipe sr = new ShapedRecipe(new ItemStack(Material.getMaterial(finalItem),Template.randomizeAmount()));
ShapedRecipe sr = new ShapedRecipe(new NamespacedKey(Template.plugin,"shapedrecipe_"+(Template.recipe_count++)),new ItemStack(Material.getMaterial(finalItem),Template.randomizeAmount()));
sr.shape(shape);
for (Character c : ingredientsMap.keySet()) {
MaterialChoice m = ingredientsMap.get(c);

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapelessRecipe;
@ -14,7 +15,7 @@ public class ShapelessRecipeStore implements RecipeStore{
@Override
public void createRecipe() {
ShapelessRecipe sr = new ShapelessRecipe(new ItemStack(Material.getMaterial(finalItem),Template.randomizeAmount()));
ShapelessRecipe sr = new ShapelessRecipe(new NamespacedKey(Template.plugin,"shapelessrecipe_"+(Template.recipe_count++)),new ItemStack(Material.getMaterial(finalItem),Template.randomizeAmount()));
for (int i=0;i<craftingitems.size();i++) {
sr.addIngredient(Material.getMaterial(craftingitems.get(i)));
Bukkit.getLogger().info(" Added ingredient "+craftingitems.get(i));

@ -65,6 +65,8 @@ public class Template
public static HashMap<EntityType,List<ItemStack>> monsterDropTable = new HashMap<EntityType,List<ItemStack>>();
public static HashMap<String,FurnaceRecipeStore> furnaceRecipeTables = new HashMap<String,FurnaceRecipeStore>();
public static ItemStack randomMelonItem;
public static int recipe_count=0;
public static boolean finished=false;
PluginDescriptionFile pdfFile;
@ -222,8 +224,11 @@ public class Template
return randomizeAmount(4);
}
public static int randomizeAmount(int amt) {
return randomizeAmount(Template.r,amt);
}
public static int randomizeAmount(Random r, int amt) {
int counter=1;
while (Template.r.nextInt(amt)==0) {
while (r.nextInt(amt)==0) {
counter++;
}
return counter;
@ -397,5 +402,7 @@ public class Template
getCommand("block").setExecutor(new ExampleCommand());
pm.registerEvents(new ExampleListener(), this);
finished=true;
}
}

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -39,6 +40,10 @@ import scramble.plugin.Template;
public class ExampleListener implements Listener {
final static String[] consonants = new String[]{"B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"};
final static String[] vowels = new String[]{"A","E","I","O","U","Y"};
@EventHandler
public void breakingTheMelons(BlockBreakEvent ev) {
if (ev.getBlock().getType()==Material.MELON) {
@ -54,16 +59,44 @@ public class ExampleListener implements Listener {
}
}
public String GenerateRandomName() {
StringBuilder name = new StringBuilder();
boolean consonant=Template.r.nextInt(2)==0;
int strlength = Template.r.nextInt(Template.randomizeAmount(2)+5);
boolean first=false;
while ((strlength--)>0) {
if (consonant) {
String letter = consonants[Template.r.nextInt(consonants.length)];
name.append(letter);
if (Template.r.nextInt(4)==0 && Math.abs(name.length()-strlength)<=3) {
name.append(letter);
}
} else {
name.append(vowels[Template.r.nextInt(vowels.length)]);
}
consonant=!consonant;
}
return name.toString();
}
@EventHandler
public void AcquireTrades(VillagerAcquireTradeEvent ev) {
if (!Template.finished) {
ev.setCancelled(true);
return;
}
//Bukkit.getLogger().info(ev.getEntity()+" getting "+ev.getRecipe());
if (ev.getEntity().getCustomName()==null || ev.getEntity().getCustomName().length()==0) {
ev.getEntity().setCustomName(GenerateRandomName());
}
Random ff = new Random(ev.getEntity().getCustomName().hashCode());
MerchantRecipe prev = ev.getRecipe();
MerchantRecipe newRecipe = new MerchantRecipe(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(Template.r.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount(2)*Template.randomizeAmount(2)),
MerchantRecipe newRecipe = new MerchantRecipe(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(ff.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount(ff,2)*Template.randomizeAmount(ff,2)),
prev.getUses(),prev.getMaxUses(),true,prev.getVillagerExperience(),prev.getPriceMultiplier());
List<ItemStack> ingredients = new ArrayList<ItemStack>();
ingredients.add(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(Template.r.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount()));
if (Template.r.nextInt(10)==0) {
ingredients.add(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(Template.r.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount()));
ingredients.add(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(ff.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount(ff,4)));
if (ff.nextInt(10)==0) {
ingredients.add(new ItemStack(Material.getMaterial(Template.archivedshufflelist.get(ff.nextInt(Template.archivedshufflelist.size()))),Template.randomizeAmount(ff,4)));
}
newRecipe.setIngredients(ingredients);
ev.setRecipe(newRecipe);
@ -95,7 +128,12 @@ public class ExampleListener implements Listener {
}
private void SpawnRandomizedEntity(LivingEntity ent) {
Bukkit.getLogger().info("ent: "+ent);
Bukkit.getLogger().info("entloc: "+ent.getLocation());
Bukkit.getLogger().info("template_breedingtable: "+Template.breedingTable);
Bukkit.getLogger().info("enttype: "+ent.getType());
Entity baby = ent.getWorld().spawnEntity(ent.getLocation(), Template.breedingTable.get(ent.getType()));
Bukkit.getLogger().info("baby: "+baby);
if (baby instanceof Ageable) {
Ageable baby_ent = (Ageable)baby;
baby_ent.setBaby();

Loading…
Cancel
Save