- 122
- 4
- 6
Здорова, буду краток, рецепт и все прилегающее к нему я запилил но проверка в самом выполнение не хочет работать
скажу сразу не работает только метод testMob, должно работать так: в крафте задаются параметры какой моб и на какой позиции, дальше он сравнивается с мобами из листа если есть совпадение по позиции и какой моб то выполняется крафт. Подсобите в этой ситуации.
Recipe:
public class MobRitualRecipe {
private final ItemStack output;
private final ImmutableList<Ingredient> inputs;
private final boolean research;
private final ImmutableList<BlockPos> positions;
private final ImmutableList<String> entities;
public MobRitualRecipe(boolean research, ItemStack output, ImmutableList<BlockPos> positions, ImmutableList<String> entities, Ingredient... inputs) {
this.research = research;
this.output = output;
ImmutableList.Builder<Ingredient> builder = ImmutableList.builder();
for (Ingredient ing : inputs) builder.add(ing);
this.inputs = builder.build();
this.positions = positions;
this.entities = entities;
}
public boolean matches(List<EntityItem> entityItems) {
List<Ingredient> inputsMissing = new ArrayList<>(inputs);
for (int i = 0; i < entityItems.size(); i++) {
ItemStack stack = entityItems.get(i).getItem();
if (stack.isEmpty()) break;
int stackIndex = -1;
for (int j = 0; j < inputsMissing.size(); j++) {
if (compareStacks(inputsMissing.get(j).getMatchingStacks()[0], stack)) {
stackIndex = j;
break;
}
}
if (stackIndex != -1) inputsMissing.remove(stackIndex);
else return false;
}
return inputsMissing.isEmpty();
}
private boolean compareStacks(ItemStack r, ItemStack s) {
return r.getItem() == s.getItem() && r.getCount() == s.getCount() && r.getItemDamage() == s.getItemDamage() && ItemNBTHelper.matchTag(r.getTagCompound(), s.getTagCompound());
}
public ItemStack getOutput() { return output; }
public ImmutableList<Ingredient> getInputs() { return inputs; }
public boolean getResearch() { return research; }
public ImmutableList<BlockPos> getBlockPos() { return positions; }
public ImmutableList<String> getEntity() { return entities; }
}
Craft:
public class CraftMobRitual {
public static final ArrayList<MobRitualRecipe> recipes = new ArrayList<>();
public static void init() {
addRecipe(false, new ItemStack(Items.NETHER_STAR),
ImmutableList.of(
new BlockPos(2, 0, 0),
new BlockPos(-2, 0, 0),
new BlockPos(0, 0, 2),
new BlockPos(0, 0, -2)
),
ImmutableList.of(
"minecraft:zombie",
"minecraft:zombie",
"minecraft:zombie",
"minecraft:zombie"
),
ing(new ItemStack(Blocks.GOLD_BLOCK)),
ing(new ItemStack(Items.WATER_BUCKET)),
ing(new ItemStack(Items.COAL)));
}
public static void addRecipe(boolean research, ItemStack output, ImmutableList<BlockPos> positions, ImmutableList<String> entity, Ingredient... inputs) {
Preconditions.checkArgument(inputs.length <= 6);
recipes.add(new MobRitualRecipe(research, output, positions, entity, inputs));
}
private static Ingredient ing(ItemStack stack) { return Ingredient.fromStacks(stack); }
private static Ingredient nbtIng(ItemStack stack) { return IngredientNBT.fromStacks(stack); }
}
Event:
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand hand, EnumFacing facing, float x, float y, float z) {
if (getTile(world, pos) != null && getTile(world, pos).getTypeRune() == 26 && getTile(world, pos).isRuneStartR()) {
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(getTile(world, pos).getPos()).grow(25));
List<EntityItem> list_items = new ArrayList<EntityItem>();
if (!entities.isEmpty()) for (Entity entity : entities) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getDistanceSq(item) <= 2 * 2) {
list_items.add(item);
}
}
if (!list_items.isEmpty()) for (EntityItem item : list_items) {
for (MobRitualRecipe recipe : CraftMobRitual.recipes) {
if (recipe.matches(list_items) && isTestMob(pos, world, entities, recipe.getBlockPos(), recipe.getEntity())) {
System.out.println("yes");
}
}
}
}
return true;
}
return false;
}
private static boolean isTestMob(BlockPos pos, World world, List<Entity> entities, ImmutableList<BlockPos> positions, ImmutableList<String> mobID) {
for (int i = 0; i < positions.size(); i++) {
BlockPos mPos = pos.add(positions.get(i));
EntityEntry entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(mobID.get(i)));
if (entry == null) return false;
for (Entity ent : entities) if (ent instanceof EntityLivingBase) {
EntityLivingBase livingBase = (EntityLivingBase) ent;
if (!testMob(mPos, world, livingBase, entry)) return false;
}
}
return true;
}
private static boolean testMob(BlockPos pos, World world, EntityLivingBase base_list, EntityEntry mob) {
Entity entity = mob.newInstance(world);
entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
if (base_list.getPosition().equals(pos) && base_list.equals(entity)) {
return true;
}
return false;
}
Последнее редактирование: