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,11 +9,12 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
*
* @author jotty
*
*/
@ -23,9 +24,18 @@ public class EmptyLavaHoarderBlockEntity extends BlockEntity {
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
*
*
* @param world the world
* @param pos the pos
* @return true if lava was found
@ -38,8 +48,7 @@ public class EmptyLavaHoarderBlockEntity extends BlockEntity {
BlockPos up = pos.up();
Random random = new Random();
if (random.nextFloat() > 0.9f) {
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(),
new ItemStack(QuickieItems.SULPHOR, 1 + new Random().nextInt(4))));
spawnRandomItems(world, up, 2);
}
return true;
}

View File

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

View File

@ -6,12 +6,14 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
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.Box;
import net.minecraft.world.World;
/**
*
*
* @author jotty
*
*/
@ -30,9 +32,12 @@ public class MonsterHoarderBlockEntity extends BlockEntity {
Box box = new Box(pos).expand(mhbe.getSuckradius());
List<Entity> entities = world.getOtherEntities(null, box);
for (Entity entity : entities) {
if (entity instanceof HostileEntity) {
HostileEntity mobEntity = (HostileEntity) entity;
mobEntity.setOnFireFor(90);
if (entity instanceof WardenEntity) {
entity.kill();
} 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 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.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
@ -15,17 +14,17 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
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.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.context.LootContext.Builder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
*
* @author jotty
*
*/
@ -40,6 +39,11 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
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
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
List<ItemStack> list = new ArrayList<>();
@ -113,12 +117,7 @@ public class BlockEmptyLavahoarder extends Block implements BlockEntityProvider
}
BlockPos up = pos.up();
if (count > 0) {
world.spawnEntity(new ItemEntity(world, up.getX(), up.getY(), up.getZ(), new ItemStack(QuickieItems.SULPHOR, 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))));
EmptyLavaHoarderBlockEntity.spawnRandomItems(world, up, 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.List;
import java.util.Random;
import de.jottyfan.minecraft.quickiefabric.blockentity.EmptyLavaHoarderBlockEntity;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -26,7 +25,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
*
*
* @author jotty
*
*/
@ -73,16 +72,7 @@ public class BlockLavahoarder extends Block implements BlockEntityProvider {
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(),
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))));
EmptyLavaHoarderBlockEntity.spawnRandomItems(world, pos, 2);
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.loot.LootPool;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
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) {
return LootPool.builder().rolls(ConstantLootNumberProvider.create(number))
.with(RandomChanceLootCondition.builder(chance))
.conditionally(RandomChanceLootCondition.builder(chance))
.with(ItemEntry.builder(item));
}
}

View File

@ -318,10 +318,10 @@ public class RegistryManager {
}
public static final void registerLootings() {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, supplier, setter) -> {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if (isGrass(id)) {
supplier.pool(LootHelper.build(1, QuickieItems.COTTONSEED, 0.125f));
supplier.pool(LootHelper.build(2, QuickieItems.SALPETER, 0.012f));
tableBuilder.pool(LootHelper.build(1, QuickieItems.COTTONSEED, 0.125f));
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": {
"item": "quickiefabric:lavahoarder",
"item": "quickiefabric:emptylavahoarder",
"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
}
}