corrected all bugs

This commit is contained in:
Jottyfan 2022-07-24 23:57:22 +02:00
parent a050b59e8f
commit a1a4741b63
11 changed files with 114 additions and 39 deletions

View File

@ -9,6 +9,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -23,6 +24,15 @@ public class EmptyLavaHoarderBlockEntity extends BlockEntity {
super(QuickieFabricBlockEntity.EMPTYLAVAHOARDER, pos, state); super(QuickieFabricBlockEntity.EMPTYLAVAHOARDER, pos, state);
} }
public static final void spawnRandomItems(World world, BlockPos pos, Integer count) {
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(QuickieItems.SULPHOR, 1 + new Random().nextInt(count))));
}
/** /**
* sucks the lava that touches the block * sucks the lava that touches the block
* *
@ -38,8 +48,7 @@ public class EmptyLavaHoarderBlockEntity extends BlockEntity {
BlockPos up = pos.up(); BlockPos up = pos.up();
Random random = new Random(); Random random = new Random();
if (random.nextFloat() > 0.9f) { if (random.nextFloat() > 0.9f) {
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), spawnRandomItems(world, up, 2);
new ItemStack(QuickieItems.SULPHOR, 1 + new Random().nextInt(4))));
} }
return true; return true;
} }

View File

@ -3,6 +3,7 @@ package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.jottyfan.minecraft.quickiefabric.text.PrefixedText;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.entity.LootableContainerBlockEntity;
@ -134,10 +135,8 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
for (ItemStack stack : stacks) { for (ItemStack stack : stacks) {
Item item = stack.getItem(); Item item = stack.getItem();
if (item != Items.AIR) { if (item != Items.AIR) {
Integer amount = stack.getCount(); Text text = PrefixedText.instance(String.format("%dx ", stack.getCount()).concat("%s"),
StringBuilder buf = new StringBuilder(String.format("%dx ", amount)); Text.translatable(stack.getTranslationKey()));
buf.append(Text.translatable(stack.getTranslationKey()).translate());
Text text = Text.of(buf.toString());
list.add(text); list.add(text);
} }
} }

View File

@ -6,6 +6,8 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.mob.PiglinEntity;
import net.minecraft.entity.mob.WardenEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -30,9 +32,12 @@ public class MonsterHoarderBlockEntity extends BlockEntity {
Box box = new Box(pos).expand(mhbe.getSuckradius()); Box box = new Box(pos).expand(mhbe.getSuckradius());
List<Entity> entities = world.getOtherEntities(null, box); List<Entity> entities = world.getOtherEntities(null, box);
for (Entity entity : entities) { for (Entity entity : entities) {
if (entity instanceof HostileEntity) { if (entity instanceof WardenEntity) {
HostileEntity mobEntity = (HostileEntity) entity; entity.kill();
mobEntity.setOnFireFor(90); } else if (entity instanceof PiglinEntity) {
entity.kill();
} else if (entity instanceof HostileEntity) {
entity.setOnFireFor(90);
} }
} }
} }

View File

@ -7,7 +7,6 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
import de.jottyfan.minecraft.quickiefabric.blockentity.EmptyLavaHoarderBlockEntity; import de.jottyfan.minecraft.quickiefabric.blockentity.EmptyLavaHoarderBlockEntity;
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockEntityProvider;
@ -15,11 +14,11 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.ExperienceOrbEntity; import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContext.Builder; import net.minecraft.loot.context.LootContext.Builder;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -40,6 +39,11 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
return new EmptyLavaHoarderBlockEntity(pos, blockState); return new EmptyLavaHoarderBlockEntity(pos, blockState);
} }
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
return (world1, pos, state1, be) -> EmptyLavaHoarderBlockEntity.tick(world1, pos, state1, be);
}
@Override @Override
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) { public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>(); List<ItemStack> list = new ArrayList<>();
@ -113,12 +117,7 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
} }
BlockPos up = pos.up(); BlockPos up = pos.up();
if (count > 0) { if (count > 0) {
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, count))); EmptyLavaHoarderBlockEntity.spawnRandomItems(world, up, count);
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.DIAMOND, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.EMERALD, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.IRON_NUGGET, new Random().nextInt(count))));
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(count))));
world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count)); world.spawnEntity(new ExperienceOrbEntity(world, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, count));
} }
} }

View File

@ -2,7 +2,6 @@ package de.jottyfan.minecraft.quickiefabric.blocks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import de.jottyfan.minecraft.quickiefabric.blockentity.EmptyLavaHoarderBlockEntity; import de.jottyfan.minecraft.quickiefabric.blockentity.EmptyLavaHoarderBlockEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -73,16 +72,7 @@ public class BlockLavahoarder extends Block implements BlockEntityProvider {
player.setStackInHand(hand, emptyBucketStack); player.setStackInHand(hand, emptyBucketStack);
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack)); world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), lavaBucketStack));
} }
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), EmptyLavaHoarderBlockEntity.spawnRandomItems(world, pos, 2);
new ItemStack(Items.DIAMOND, new Random().nextInt(2))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.EMERALD, new Random().nextInt(2))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.GOLD_NUGGET, new Random().nextInt(2))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.IRON_NUGGET, new Random().nextInt(2))));
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.LAPIS_LAZULI, new Random().nextInt(2))));
world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getDefaultState()); world.setBlockState(pos, QuickieBlocks.EMPTYLAVAHOARDER.getDefaultState());
} }
} }

View File

@ -2,6 +2,7 @@ package de.jottyfan.minecraft.quickiefabric.init;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.loot.LootPool; import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry; import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider; import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
@ -19,7 +20,7 @@ public class LootHelper {
*/ */
public static final LootPool.Builder build(Integer number, Item item, float chance) { public static final LootPool.Builder build(Integer number, Item item, float chance) {
return LootPool.builder().rolls(ConstantLootNumberProvider.create(number)) return LootPool.builder().rolls(ConstantLootNumberProvider.create(number))
.with(RandomChanceLootCondition.builder(chance)) .conditionally(RandomChanceLootCondition.builder(chance))
.with(ItemEntry.builder(item)); .with(ItemEntry.builder(item));
} }
} }

View File

@ -318,10 +318,10 @@ public class RegistryManager {
} }
public static final void registerLootings() { public static final void registerLootings() {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, supplier, setter) -> { LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if (isGrass(id)) { if (isGrass(id)) {
supplier.pool(LootHelper.build(1, QuickieItems.COTTONSEED, 0.125f)); tableBuilder.pool(LootHelper.build(1, QuickieItems.COTTONSEED, 0.125f));
supplier.pool(LootHelper.build(2, QuickieItems.SALPETER, 0.012f)); tableBuilder.pool(LootHelper.build(2, QuickieItems.SALPETER, 0.012f));
} }
}); });
} }

View File

@ -0,0 +1,52 @@
package de.jottyfan.minecraft.quickiefabric.text;
import java.util.List;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;
/**
*
* @author jotty
*
*/
public class PrefixedText implements Text {
private final String pattern;
private final Text text;
private PrefixedText(String pattern, Text text) {
this.pattern = pattern;
this.text = text;
}
public final static PrefixedText instance(String pattern, Text text) {
return new PrefixedText(pattern, text);
}
private Text generateText() {
return Text.of(pattern.replace("%s", text.getString()));
}
@Override
public OrderedText asOrderedText() {
return generateText().asOrderedText();
}
@Override
public TextContent getContent() {
return generateText().getContent();
}
@Override
public List<Text> getSiblings() {
return generateText().getSiblings();
}
@Override
public Style getStyle() {
return text.getStyle();
}
}

View File

@ -14,7 +14,7 @@
} }
}, },
"result": { "result": {
"item": "quickiefabric:lavahoarder", "item": "quickiefabric:emptylavahoarder",
"count": 1 "count": 1
} }
} }

View File

@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"ooo",
"oso",
"ooo"
],
"key": {
"o": {
"item": "quickiefabric:speedpowder"
},
"s": {
"item": "minecraft:barrel"
}
},
"result": {
"item": "quickiefabric:itemhoarder",
"count": 1
}
}