corrected all bugs
This commit is contained in:
parent
a050b59e8f
commit
a1a4741b63
@ -9,6 +9,7 @@ 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;
|
||||
|
||||
@ -23,6 +24,15 @@ 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
|
||||
*
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ 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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,11 +14,11 @@ 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;
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "quickiefabric:lavahoarder",
|
||||
"item": "quickiefabric:emptylavahoarder",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user