corrected all bugs
This commit is contained in:
parent
a050b59e8f
commit
a1a4741b63
@ -9,11 +9,12 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -23,9 +24,18 @@ 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
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world
|
||||||
* @param pos the pos
|
* @param pos the pos
|
||||||
* @return true if lava was found
|
* @return true if lava was found
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,17 +14,17 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -26,7 +25,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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": {
|
"result": {
|
||||||
"item": "quickiefabric:lavahoarder",
|
"item": "quickiefabric:emptylavahoarder",
|
||||||
"count": 1
|
"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