From feffc61a247cb7527f93332eae18636106b388fd Mon Sep 17 00:00:00 2001 From: pixar02 Date: Wed, 8 Nov 2023 22:01:34 +0100 Subject: [PATCH 1/4] Gamerules rule (3 new)! --- .../generated/assets/minelabs/lang/en_us.json | 4 ++ .../generated/assets/minelabs/lang/nl_be.json | 4 ++ .../generated/assets/minelabs/lang/nl_nl.json | 4 ++ .../blocks/stripped_warped_stem.json | 66 +++++++++++++++++++ src/main/java/be/minelabs/Minelabs.java | 2 + .../block/blocks/QuantumfieldBlock.java | 40 +++++++++-- .../minelabs/entity/BohrBlueprintEntity.java | 41 +++++++----- src/main/java/be/minelabs/item/Items.java | 36 +++++++--- .../be/minelabs/item/items/GasPotion.java | 18 ++--- .../be/minelabs/world/MinelabsGameRules.java | 20 ++++++ .../assets/minelabs/lang/en_us.static.json | 5 ++ .../assets/minelabs/lang/nl_be.static.json | 5 ++ 12 files changed, 202 insertions(+), 43 deletions(-) create mode 100644 src/main/generated/data/minelabs/loot_tables/lasertool/blocks/stripped_warped_stem.json create mode 100644 src/main/java/be/minelabs/world/MinelabsGameRules.java diff --git a/src/main/generated/assets/minelabs/lang/en_us.json b/src/main/generated/assets/minelabs/lang/en_us.json index 42e2ad969..9d8b926f6 100644 --- a/src/main/generated/assets/minelabs/lang/en_us.json +++ b/src/main/generated/assets/minelabs/lang/en_us.json @@ -65,6 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropy Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomic Particle", + "gamerule.allow_chemical_projectiles": "Allow chemicals to be thrown", + "gamerule.bohr_projectiles": "Should Bohr shoot items as projectiles", + "gamerule.random_quantum_drops": "Should Quantum blocks drop random items", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", @@ -324,6 +327,7 @@ "text.minelabs.inactive": "Inactive", "text.minelabs.invalid": "Incomplete Molecule", "text.minelabs.multiple_molecules": "Too many molecules", + "text.minelabs.no_chemical_projectiles": "A Gamerule prevents you from throwing chemicals!", "text.minelabs.not_implemented": "Molecule is not implemented", "text.minelabs.quark.color.blue": "Color: Blue", "text.minelabs.quark.color.green": "Color: Green", diff --git a/src/main/generated/assets/minelabs/lang/nl_be.json b/src/main/generated/assets/minelabs/lang/nl_be.json index 782ed5271..a15660a77 100644 --- a/src/main/generated/assets/minelabs/lang/nl_be.json +++ b/src/main/generated/assets/minelabs/lang/nl_be.json @@ -65,6 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropie Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomisch Deeltje", + "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", + "gamerule.bohr_projectiles": "Kan Bohr items afschieten", + "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", @@ -324,6 +327,7 @@ "text.minelabs.inactive": "Inactief", "text.minelabs.invalid": "Onvolledige Molecule", "text.minelabs.multiple_molecules": "Te veel moleculen", + "text.minelabs.no_chemical_projectiles": "Een Gameregel verbied het gooien van Chemicalien!", "text.minelabs.not_implemented": "Molecule zit niet in het spel", "text.minelabs.quark.color.blue": "Kleur: Blauw", "text.minelabs.quark.color.green": "Kleur: Groen", diff --git a/src/main/generated/assets/minelabs/lang/nl_nl.json b/src/main/generated/assets/minelabs/lang/nl_nl.json index 782ed5271..a15660a77 100644 --- a/src/main/generated/assets/minelabs/lang/nl_nl.json +++ b/src/main/generated/assets/minelabs/lang/nl_nl.json @@ -65,6 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropie Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomisch Deeltje", + "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", + "gamerule.bohr_projectiles": "Kan Bohr items afschieten", + "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", @@ -324,6 +327,7 @@ "text.minelabs.inactive": "Inactief", "text.minelabs.invalid": "Onvolledige Molecule", "text.minelabs.multiple_molecules": "Te veel moleculen", + "text.minelabs.no_chemical_projectiles": "Een Gameregel verbied het gooien van Chemicalien!", "text.minelabs.not_implemented": "Molecule zit niet in het spel", "text.minelabs.quark.color.blue": "Kleur: Blauw", "text.minelabs.quark.color.green": "Kleur: Groen", diff --git a/src/main/generated/data/minelabs/loot_tables/lasertool/blocks/stripped_warped_stem.json b/src/main/generated/data/minelabs/loot_tables/lasertool/blocks/stripped_warped_stem.json new file mode 100644 index 000000000..a180c407e --- /dev/null +++ b/src/main/generated/data/minelabs/loot_tables/lasertool/blocks/stripped_warped_stem.json @@ -0,0 +1,66 @@ +{ + "pools": [ + { + "entries": [ + { + "type": "minecraft:alternatives", + "children": [ + { + "type": "minecraft:group", + "children": [ + { + "type": "minecraft:loot_table", + "functions": [ + { + "enchantment": "minecraft:fortune", + "formula": "minecraft:ore_drops", + "function": "minecraft:apply_bonus" + } + ], + "name": "minelabs:lasertool/blocks/mushroom_stem", + "weight": 100 + } + ], + "conditions": [ + { + "condition": "minecraft:alternative", + "terms": [ + { + "condition": "minecraft:match_tool", + "predicate": { + "items": [ + "minelabs:lasertool_iron" + ] + } + }, + { + "condition": "minecraft:match_tool", + "predicate": { + "items": [ + "minelabs:lasertool_gold" + ] + } + }, + { + "condition": "minecraft:match_tool", + "predicate": { + "items": [ + "minelabs:lasertool_diamond" + ] + } + } + ] + } + ] + }, + { + "type": "minecraft:loot_table", + "name": "minecraft:blocks/stripped_warped_stem" + } + ] + } + ], + "rolls": 1 + } + ] +} \ No newline at end of file diff --git a/src/main/java/be/minelabs/Minelabs.java b/src/main/java/be/minelabs/Minelabs.java index 1300fc8f9..b295087c8 100644 --- a/src/main/java/be/minelabs/Minelabs.java +++ b/src/main/java/be/minelabs/Minelabs.java @@ -5,6 +5,7 @@ import be.minelabs.block.ExtraDispenserBehavior; import be.minelabs.block.entity.BlockEntities; import be.minelabs.recipe.CraftingRecipes; +import be.minelabs.world.MinelabsGameRules; import be.minelabs.world.dimension.ModDimensions; import be.minelabs.entity.effect.Effects; import be.minelabs.entity.Entities; @@ -53,6 +54,7 @@ public void onInitialize() { CraftingRecipes.onInitialize(); Villagers.onInitialize(); + MinelabsGameRules.onInitialize(); ServerModEvents.onInitialize(); Criteria.onInitialize(); } diff --git a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java index 12587264d..77e1718b3 100644 --- a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java +++ b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java @@ -2,7 +2,9 @@ import be.minelabs.block.Blocks; import be.minelabs.block.entity.QuantumFieldBlockEntity; +import be.minelabs.item.Items; import be.minelabs.state.property.Properties; +import be.minelabs.world.MinelabsGameRules; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; @@ -10,8 +12,11 @@ import net.minecraft.block.Material; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.loot.context.LootContext; import net.minecraft.server.world.ServerWorld; +import net.minecraft.stat.Stats; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.IntProperty; @@ -23,6 +28,9 @@ import net.minecraft.world.WorldAccess; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; + public class QuantumfieldBlock extends Block implements BlockEntityProvider { public static final int MAX_AGE = 10; public static final int DECAYRATE = 1; @@ -33,6 +41,7 @@ public class QuantumfieldBlock extends Block implements BlockEntityProvider { public static final BooleanProperty MASTER = Properties.MASTER; public static final IntProperty AGE = IntProperty.of("age", 0, MAX_AGE); + public static final IntProperty DROP_KIND = IntProperty.of("kind", 0, 5); public QuantumfieldBlock() { @@ -45,7 +54,7 @@ public QuantumfieldBlock() { .ticksRandomly() .luminance(state -> (int) Math.ceil(MathHelper.clampedLerp(MAX_LIGHT, MIN_LIGHT, (float) getAge(state) / MAX_AGE))) ); - this.setDefaultState(getDefaultState().with(AGE, 0).with(MASTER, false)); + this.setDefaultState(getDefaultState().with(AGE, 0).with(MASTER, false).with(DROP_KIND, 0)); } @@ -53,7 +62,7 @@ public static boolean isMaster(BlockState state) { return state.get(MASTER); } - public static int getAge(BlockState state){ + public static int getAge(BlockState state) { return state.get(AGE); } @@ -85,15 +94,15 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio } return state.with(AGE, age); } - return super.getStateForNeighborUpdate(state,direction,neighborState,world,pos,neighborPos); + return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); } @Override protected void appendProperties(StateManager.Builder builder) { - builder.add(AGE, MASTER); + builder.add(AGE, MASTER, DROP_KIND); } - public void removeQuantumBlockIfNeeded(BlockState state, ServerWorld world, BlockPos pos){ + public void removeQuantumBlockIfNeeded(BlockState state, ServerWorld world, BlockPos pos) { if (MAX_AGE == getAge(state)) { world.removeBlock(pos, false); if (pos.getY() == AtomicFloor.ATOMIC_FLOOR_LAYER) { @@ -104,7 +113,7 @@ public void removeQuantumBlockIfNeeded(BlockState state, ServerWorld world, Bloc @Override public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - removeQuantumBlockIfNeeded(state,world,pos); + removeQuantumBlockIfNeeded(state, world, pos); super.scheduledTick(state, world, pos, random); } @@ -121,7 +130,24 @@ public BlockEntity createMasterBlockEntity(BlockPos pos, BlockState state) { public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack) { super.afterBreak(world, player, pos, state, blockEntity, stack); if (!world.isClient()) { - world.setBlockState(pos, state,Block.NOTIFY_ALL); + int drop = state.get(DROP_KIND); + drop++; + if (drop >= 6) { + drop = 0; + } + world.setBlockState(pos, state.with(DROP_KIND, drop), Block.NOTIFY_ALL); + } + } + + @Override + public List getDroppedStacks(BlockState state, LootContext.Builder builder) { + if (builder.getWorld().getGameRules().getBoolean(MinelabsGameRules.RANDOM_QUANTUM_DROPS)) { + return super.getDroppedStacks(state, builder); + } else { + boolean down = getTranslationKey().contains("downquark"); + return List.of(new ItemStack( + down ? Items.down_stacks.get(state.get(DROP_KIND)) : Items.up_stacks.get(state.get(DROP_KIND)) + )); } } } diff --git a/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java b/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java index 867a96753..ad49c711a 100644 --- a/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java +++ b/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java @@ -10,6 +10,7 @@ import be.minelabs.item.Items; import be.minelabs.mixin.FishingBobberEntityAccessor; import be.minelabs.util.AtomConfiguration; +import be.minelabs.world.MinelabsGameRules; import net.minecraft.block.BlockState; import net.minecraft.block.piston.PistonBehavior; import net.minecraft.entity.*; @@ -132,9 +133,13 @@ private void logicalTick() { if (getAtomConfig().isElectronDecomposing()) { electronEjectProgress -= electronEjectProgressPerTick * getAtomConfig().getDecomposingElectronCount(); - if (electronEjectProgress <= 0f){ - if(removeItem(Items.ELECTRON)) - launchParticle(Items.ELECTRON); + if (electronEjectProgress <= 0f) { + if (removeItem(Items.ELECTRON)) + if (world.getGameRules().getBoolean(MinelabsGameRules.BOHR_PROJECTILES)) { + launchParticle(Items.ELECTRON); + } else { + dropStack(new ItemStack(Items.ELECTRON)); + } electronEjectProgress = 1f; } } @@ -170,7 +175,7 @@ protected void initDataTracker() { public void remove(RemovalReason reason) { super.remove(reason); // cleanup after entity is removed - if (reason.shouldDestroy()){ + if (reason.shouldDestroy()) { dropContents(); BlockState state = world.getBlockState(getBohrBlueprintPos()); if (state.isOf(Blocks.BOHR_BLUEPRINT)) @@ -330,12 +335,16 @@ private void launchParticle(Item item) { world.spawnEntity(entity); } - private void decomposeAtom() { - for (int p = 0; p < getProtons(); p++) launchParticle(Items.PROTON); - for (int n = 0; n < getNeutrons(); n++) launchParticle(Items.NEUTRON); - for (int e = 0; e < getElectrons(); e++) launchParticle(Items.ELECTRON); - clear(); + private void decomposeAtom() { + if (world.getGameRules().getBoolean(MinelabsGameRules.BOHR_PROJECTILES)) { + for (int p = 0; p < getProtons(); p++) launchParticle(Items.PROTON); + for (int n = 0; n < getNeutrons(); n++) launchParticle(Items.NEUTRON); + for (int e = 0; e < getElectrons(); e++) launchParticle(Items.ELECTRON); + clear(); + } else { + dropContents(); + } } private void clear() { @@ -430,11 +439,11 @@ public void readNbt(NbtCompound nbt) { // Remove other bohr blueprint entities already present. // We put this check here because the position needs to be known and it is loaded from nbt, for example when copied by structure block - if (!world.isClient){ + if (!world.isClient) { List entities = world.getOtherEntities(this, getBoundingBox(), e -> e instanceof BohrBlueprintEntity); - for (Entity entity: entities){ + for (Entity entity : entities) { // move below map first so the bohr plate below won't be found and it doesn't destroy it. - entity.setPosition(getX(), world.getBottomY()-1, getZ()); + entity.setPosition(getX(), world.getBottomY() - 1, getZ()); entity.discard(); } } @@ -461,7 +470,7 @@ protected void writeCustomDataToNbt(NbtCompound nbt) { @Override protected void readCustomDataFromNbt(NbtCompound nbt) { inventory.clear(); - if (nbt.contains("Items")){ + if (nbt.contains("Items")) { // load inventory NbtList nbtList = nbt.getList("Items", NbtElement.COMPOUND_TYPE); for (int i = 0; i < nbtList.size(); i++) { @@ -529,7 +538,7 @@ private void compositionChanged() { // set block state BohrBlueprintBlock.Status status = BohrBlueprintBlock.Status.EMPTY; if (!getCraftableAtom().isEmpty()) status = BohrBlueprintBlock.Status.CRAFTABLE; - else if(!getAtomConfig().isStable()) status = BohrBlueprintBlock.Status.UNSTABLE; + else if (!getAtomConfig().isStable()) status = BohrBlueprintBlock.Status.UNSTABLE; BohrBlueprintBlock.updateStatus(world, getBohrBlueprintPos(), status); } @@ -537,11 +546,11 @@ public AtomConfiguration getAtomConfig() { return dataTracker.get(ATOM_CONFIGURATION); } - protected void setAtomConfiguration(int protons, int neutrons, int electrons){ + protected void setAtomConfiguration(int protons, int neutrons, int electrons) { setAtomConfiguration(new AtomConfiguration(protons, neutrons, electrons)); } - protected void setAtomConfiguration(AtomConfiguration atomConfig){ + protected void setAtomConfiguration(AtomConfiguration atomConfig) { dataTracker.set(ATOM_CONFIGURATION, atomConfig); } diff --git a/src/main/java/be/minelabs/item/Items.java b/src/main/java/be/minelabs/item/Items.java index 1620167eb..6190e257d 100644 --- a/src/main/java/be/minelabs/item/Items.java +++ b/src/main/java/be/minelabs/item/Items.java @@ -14,6 +14,7 @@ import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -181,15 +182,6 @@ public class Items { public static final Item BOND = register(new Item(new Item.Settings()), "bond"); public static final Item VALENCEE = register(new Item(new Item.Settings()), "valence_electrons"); - // Items > Quantum fields - public static final Item UPQUARK_QUANTUMFIELD = register(new BlockItem(Blocks.UPQUARK_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/upquark_quantumfield"); - public static final Item DOWNQUARK_QUANTUMFIELD = register(new BlockItem(Blocks.DOWNQUARK_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/downquark_quantumfield"); - public static final Item GLUON_QUANTUMFIELD = register(new BlockItem(Blocks.GLUON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/gluon_quantumfield"); - public static final Item ELECTRON_QUANTUMFIELD = register(new BlockItem(Blocks.ELECTRON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/electron_quantumfield"); - public static final Item PHOTON_QUANTUMFIELD = register(new BlockItem(Blocks.PHOTON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/photon_quantumfield"); - public static final Item NEUTRINO_QUANTUMFIELD = register(new BlockItem(Blocks.NEUTRINO_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/neutrino_quantumfield"); - public static final Item WEAK_BOSON_QUANTUMFIELD = register(new BlockItem(Blocks.WEAK_BOSON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/weak_boson_quantumfield"); - // Items > Electric field public static final Item TIME_FREEZE_BLOCK = register(new BlockItem(Blocks.TIME_FREEZE_BLOCK, new FabricItemSettings()), "time_freeze_block"); @@ -226,6 +218,17 @@ public class Items { public static final Item PION_MINUS = register(new BlockItem(Blocks.PION_MINUS, new FabricItemSettings()), "subatomic/pion_minus"); public static final Item PION_PLUS = register(new BlockItem(Blocks.PION_PLUS, new FabricItemSettings()), "subatomic/pion_plus"); + + // Items > Quantum fields + public static final Item UPQUARK_QUANTUMFIELD = register(new BlockItem(Blocks.UPQUARK_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/upquark_quantumfield"); + public static final Item DOWNQUARK_QUANTUMFIELD = register(new BlockItem(Blocks.DOWNQUARK_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/downquark_quantumfield"); + public static final Item GLUON_QUANTUMFIELD = register(new BlockItem(Blocks.GLUON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/gluon_quantumfield"); + public static final Item ELECTRON_QUANTUMFIELD = register(new BlockItem(Blocks.ELECTRON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/electron_quantumfield"); + public static final Item PHOTON_QUANTUMFIELD = register(new BlockItem(Blocks.PHOTON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/photon_quantumfield"); + public static final Item NEUTRINO_QUANTUMFIELD = register(new BlockItem(Blocks.NEUTRINO_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/neutrino_quantumfield"); + public static final Item WEAK_BOSON_QUANTUMFIELD = register(new BlockItem(Blocks.WEAK_BOSON_QUANTUMFIELD, new FabricItemSettings()), "quantumfield/weak_boson_quantumfield"); + + public static final Item CHARGED_POINT = register(new BlockItem(Blocks.CHARGED_POINT_BLOCK, new FabricItemSettings()), "charged_point"); public static final Item ELECTRIC_FIELD_SENSOR = register(new BlockItem(Blocks.ELECTRIC_FIELD_SENSOR_BLOCK, new FabricItemSettings()), "electric_field_sensor"); @@ -329,6 +332,21 @@ public class Items { public static final Item ERLENMEYER_SICL4 = register(new ErlenmeyerItem( Fluids.STILL_SiCl4, new Item.Settings().recipeRemainder(ERLENMEYER), "SiCl4"), "erlenmeyer/erlenmeyer_sicl4"); + public static final List up_stacks = new ArrayList<>(List.of( + Items.UPQUARK_RED, + Items.UPQUARK_GREEN, + Items.UPQUARK_BLUE, + Items.ANTI_UPQUARK_RED, + Items.ANTI_UPQUARK_GREEN, + Items.ANTI_UPQUARK_BLUE)); + + public static final List down_stacks = new ArrayList<>(List.of( + Items.DOWNQUARK_RED, + Items.DOWNQUARK_GREEN, + Items.DOWNQUARK_BLUE, + Items.ANTI_DOWNQUARK_RED, + Items.ANTI_DOWNQUARK_GREEN, + Items.ANTI_DOWNQUARK_BLUE)); /** * Register an Item diff --git a/src/main/java/be/minelabs/item/items/GasPotion.java b/src/main/java/be/minelabs/item/items/GasPotion.java index c41ef1ca6..8718eddf1 100644 --- a/src/main/java/be/minelabs/item/items/GasPotion.java +++ b/src/main/java/be/minelabs/item/items/GasPotion.java @@ -6,6 +6,7 @@ import be.minelabs.item.IMoleculeItem; import be.minelabs.item.Items; import be.minelabs.science.Molecule; +import be.minelabs.world.MinelabsGameRules; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -32,17 +33,6 @@ public GasPotion(Settings settings, Molecule molecule) { this.molecule = molecule; } - /*TODO : NO LONGER NEEDED ? - @Override - public void appendStacks(ItemGroup group, DefaultedList stacks) { - Potion potion = new Potion("Test"); - if (this.isIn(group)) { - ItemStack item = PotionUtil.setPotion(new ItemStack(this), potion); - item.setNbt(null); - stacks.add(item); - } - }*/ - @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { molecule.makeTooltip(tooltip); @@ -56,6 +46,12 @@ public ItemStack getDefaultStack() { @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { ItemStack itemStack = user.getStackInHand(hand); + + if (!world.getGameRules().getBoolean(MinelabsGameRules.ALLOW_CHEMICAL_PROJECTILES)) { + user.sendMessage(Text.translatable("text.minelabs.no_chemical_projectiles")); + return TypedActionResult.fail(itemStack); + } + if (!world.isClient) { GasPotionEntity gasEntity = new GasPotionEntity(world, user, this.molecule); gasEntity.setItem(itemStack); diff --git a/src/main/java/be/minelabs/world/MinelabsGameRules.java b/src/main/java/be/minelabs/world/MinelabsGameRules.java new file mode 100644 index 000000000..7b3cc6b48 --- /dev/null +++ b/src/main/java/be/minelabs/world/MinelabsGameRules.java @@ -0,0 +1,20 @@ +package be.minelabs.world; + +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; +import net.minecraft.world.GameRules; + +public class MinelabsGameRules { + + public static final GameRules.Key RANDOM_QUANTUM_DROPS = GameRuleRegistry.register( + "random_quantum_drops", GameRules.Category.DROPS, GameRuleFactory.createBooleanRule(true)); + + public static final GameRules.Key BOHR_PROJECTILES = GameRuleRegistry.register( + "bohr_projectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); + + public static final GameRules.Key ALLOW_CHEMICAL_PROJECTILES = GameRuleRegistry.register( + "allow_chemical_projectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); + + public static void onInitialize() { + } +} diff --git a/src/main/resources/assets/minelabs/lang/en_us.static.json b/src/main/resources/assets/minelabs/lang/en_us.static.json index fe651a721..818931881 100644 --- a/src/main/resources/assets/minelabs/lang/en_us.static.json +++ b/src/main/resources/assets/minelabs/lang/en_us.static.json @@ -24,6 +24,11 @@ "text.minelabs.anti_quark.color.red": "Color: Anti-Red", "text.minelabs.anti_quark.color.green": "Color: Anti-Green", "text.minelabs.anti_quark.color.blue": "Color: Anti-Blue", + + "gamerule.random_quantum_drops": "Should Quantum blocks drop random items", + "gamerule.bohr_projectiles": "Should Bohr shoot items as projectiles", + "gamerule.allow_chemical_projectiles": "Allow chemicals to be thrown", + "text.minelabs.no_chemical_projectiles": "A Gamerule prevents you from throwing chemicals!", "block.minelabs.charged_point": "Point Charge", "block.minelabs.fire.green_fire": "Green Fire", "block.minelabs.chemical.ccl4": "Carbon Tetrachloride (CCl\u2084)", diff --git a/src/main/resources/assets/minelabs/lang/nl_be.static.json b/src/main/resources/assets/minelabs/lang/nl_be.static.json index 0eb92b9bd..bf5a94390 100644 --- a/src/main/resources/assets/minelabs/lang/nl_be.static.json +++ b/src/main/resources/assets/minelabs/lang/nl_be.static.json @@ -24,6 +24,11 @@ "text.minelabs.anti_quark.color.red": "Kleur: Anti-Rood", "text.minelabs.anti_quark.color.green": "Kleur: Anti-Groen", "text.minelabs.anti_quark.color.blue": "Kleur: Anti-Blauw", + + "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", + "gamerule.bohr_projectiles": "Kan Bohr items afschieten", + "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", + "text.minelabs.no_chemical_projectiles": "Een Gameregel verbied het gooien van Chemicalien!", "block.minelabs.chemical.ccl4": "Tetrachloormethaan (CCl\u2084)", "block.minelabs.chemical.ch4o": "Methanol (CH\u2084O)", "block.minelabs.chemical.cs2": "Koolstofdisulfide (CS\u2082)", From e58507dadfa656352bafc0ec722fc82102141b99 Mon Sep 17 00:00:00 2001 From: pixar02 Date: Thu, 9 Nov 2023 12:39:48 +0100 Subject: [PATCH 2/4] PR requests --- .../block/blocks/QuantumfieldBlock.java | 13 ++++---- .../minelabs/entity/BohrBlueprintEntity.java | 30 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java index 77e1718b3..81ba76271 100644 --- a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java +++ b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java @@ -1,5 +1,6 @@ package be.minelabs.block.blocks; +import be.minelabs.Minelabs; import be.minelabs.block.Blocks; import be.minelabs.block.entity.QuantumFieldBlockEntity; import be.minelabs.item.Items; @@ -41,7 +42,7 @@ public class QuantumfieldBlock extends Block implements BlockEntityProvider { public static final BooleanProperty MASTER = Properties.MASTER; public static final IntProperty AGE = IntProperty.of("age", 0, MAX_AGE); - public static final IntProperty DROP_KIND = IntProperty.of("kind", 0, 5); + public static final IntProperty DROP_KIND = IntProperty.of("kind", 0, 2); public QuantumfieldBlock() { @@ -132,7 +133,7 @@ public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockStat if (!world.isClient()) { int drop = state.get(DROP_KIND); drop++; - if (drop >= 6) { + if (drop % 3 == 0) { drop = 0; } world.setBlockState(pos, state.with(DROP_KIND, drop), Block.NOTIFY_ALL); @@ -145,9 +146,11 @@ public List getDroppedStacks(BlockState state, LootContext.Builder bu return super.getDroppedStacks(state, builder); } else { boolean down = getTranslationKey().contains("downquark"); - return List.of(new ItemStack( - down ? Items.down_stacks.get(state.get(DROP_KIND)) : Items.up_stacks.get(state.get(DROP_KIND)) - )); + int kind = state.get(DROP_KIND); + Minelabs.LOGGER.info("KIND NUM: " + kind); + return List.of( + new ItemStack(down ? Items.down_stacks.get(kind) : Items.up_stacks.get(kind)), + new ItemStack(down ? Items.down_stacks.get(kind + 3) : Items.up_stacks.get(kind + 3))); } } } diff --git a/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java b/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java index ad49c711a..872e6a203 100644 --- a/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java +++ b/src/main/java/be/minelabs/entity/BohrBlueprintEntity.java @@ -33,6 +33,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import software.bernie.shadowed.eliotlash.mclib.math.functions.limit.Min; import java.util.List; import java.util.ListIterator; @@ -135,11 +136,7 @@ private void logicalTick() { if (electronEjectProgress <= 0f) { if (removeItem(Items.ELECTRON)) - if (world.getGameRules().getBoolean(MinelabsGameRules.BOHR_PROJECTILES)) { - launchParticle(Items.ELECTRON); - } else { - dropStack(new ItemStack(Items.ELECTRON)); - } + tryLaunchParticle(Items.ELECTRON); electronEjectProgress = 1f; } } @@ -335,18 +332,27 @@ private void launchParticle(Item item) { world.spawnEntity(entity); } - - private void decomposeAtom() { + /** + * Try to Launch this particle + * Will drop if GameRule doesn't allow projectile + * + * @param item : item to launch/drop + */ + public void tryLaunchParticle(Item item) { if (world.getGameRules().getBoolean(MinelabsGameRules.BOHR_PROJECTILES)) { - for (int p = 0; p < getProtons(); p++) launchParticle(Items.PROTON); - for (int n = 0; n < getNeutrons(); n++) launchParticle(Items.NEUTRON); - for (int e = 0; e < getElectrons(); e++) launchParticle(Items.ELECTRON); - clear(); + launchParticle(item); } else { - dropContents(); + dropStack(new ItemStack(item)); } } + private void decomposeAtom() { + for (int p = 0; p < getProtons(); p++) tryLaunchParticle(Items.PROTON); + for (int n = 0; n < getNeutrons(); n++) tryLaunchParticle(Items.NEUTRON); + for (int e = 0; e < getElectrons(); e++) tryLaunchParticle(Items.ELECTRON); + clear(); + } + private void clear() { inventory.clear(); // sets everything to zero From 84fe7348232407520ccd5cef801e80fad17f1a9d Mon Sep 17 00:00:00 2001 From: pixar02 Date: Thu, 9 Nov 2023 13:18:25 +0100 Subject: [PATCH 3/4] removed print --- src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java index 81ba76271..2d58e5740 100644 --- a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java +++ b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java @@ -147,7 +147,6 @@ public List getDroppedStacks(BlockState state, LootContext.Builder bu } else { boolean down = getTranslationKey().contains("downquark"); int kind = state.get(DROP_KIND); - Minelabs.LOGGER.info("KIND NUM: " + kind); return List.of( new ItemStack(down ? Items.down_stacks.get(kind) : Items.up_stacks.get(kind)), new ItemStack(down ? Items.down_stacks.get(kind + 3) : Items.up_stacks.get(kind + 3))); From 4f55c5c830b31c6f95c06c8aab9f22b0a4f48d73 Mon Sep 17 00:00:00 2001 From: pixar02 Date: Thu, 9 Nov 2023 22:29:12 +0100 Subject: [PATCH 4/4] small fix + change naming to mc convention --- src/main/generated/assets/minelabs/lang/en_us.json | 6 +++--- src/main/generated/assets/minelabs/lang/nl_be.json | 6 +++--- src/main/generated/assets/minelabs/lang/nl_nl.json | 6 +++--- .../java/be/minelabs/block/blocks/QuantumfieldBlock.java | 7 ++----- src/main/java/be/minelabs/world/MinelabsGameRules.java | 6 +++--- src/main/resources/assets/minelabs/lang/en_us.static.json | 7 +++---- src/main/resources/assets/minelabs/lang/nl_be.static.json | 7 +++---- 7 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/generated/assets/minelabs/lang/en_us.json b/src/main/generated/assets/minelabs/lang/en_us.json index 9d8b926f6..8bb3cfa87 100644 --- a/src/main/generated/assets/minelabs/lang/en_us.json +++ b/src/main/generated/assets/minelabs/lang/en_us.json @@ -65,9 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropy Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomic Particle", - "gamerule.allow_chemical_projectiles": "Allow chemicals to be thrown", - "gamerule.bohr_projectiles": "Should Bohr shoot items as projectiles", - "gamerule.random_quantum_drops": "Should Quantum blocks drop random items", + "gamerule.allowChemicalProjectiles": "Allow chemicals to be thrown", + "gamerule.bohrProjectiles": "Should Bohr shoot items as projectiles", + "gamerule.randomQuantumDrops": "Should Quantum blocks drop random items", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", diff --git a/src/main/generated/assets/minelabs/lang/nl_be.json b/src/main/generated/assets/minelabs/lang/nl_be.json index a15660a77..01c036f45 100644 --- a/src/main/generated/assets/minelabs/lang/nl_be.json +++ b/src/main/generated/assets/minelabs/lang/nl_be.json @@ -65,9 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropie Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomisch Deeltje", - "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", - "gamerule.bohr_projectiles": "Kan Bohr items afschieten", - "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", + "gamerule.allowChemicalProjectiles": "Kan je met Chemicalien gooien", + "gamerule.bohrProjectiles": "Kan Bohr items afschieten", + "gamerule.randomQuantumDrops": "Horen Kwantumblokken willekeurige items te laten vallen", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", diff --git a/src/main/generated/assets/minelabs/lang/nl_nl.json b/src/main/generated/assets/minelabs/lang/nl_nl.json index a15660a77..01c036f45 100644 --- a/src/main/generated/assets/minelabs/lang/nl_nl.json +++ b/src/main/generated/assets/minelabs/lang/nl_nl.json @@ -65,9 +65,9 @@ "entity.minelabs.corrosive": "missing_translation", "entity.minelabs.entropy_creeper": "Entropie Creeper", "entity.minelabs.subatomic_particle_entity": "Subatomisch Deeltje", - "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", - "gamerule.bohr_projectiles": "Kan Bohr items afschieten", - "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", + "gamerule.allowChemicalProjectiles": "Kan je met Chemicalien gooien", + "gamerule.bohrProjectiles": "Kan Bohr items afschieten", + "gamerule.randomQuantumDrops": "Horen Kwantumblokken willekeurige items te laten vallen", "item.minelabs.atom.actinium_atom": "Actinium", "item.minelabs.atom.aluminium_atom": "Aluminium", "item.minelabs.atom.americium_atom": "Americium", diff --git a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java index 2d58e5740..f25301a3c 100644 --- a/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java +++ b/src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java @@ -1,6 +1,5 @@ package be.minelabs.block.blocks; -import be.minelabs.Minelabs; import be.minelabs.block.Blocks; import be.minelabs.block.entity.QuantumFieldBlockEntity; import be.minelabs.item.Items; @@ -13,11 +12,9 @@ import net.minecraft.block.Material; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.loot.context.LootContext; import net.minecraft.server.world.ServerWorld; -import net.minecraft.stat.Stats; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.IntProperty; @@ -29,7 +26,6 @@ import net.minecraft.world.WorldAccess; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; public class QuantumfieldBlock extends Block implements BlockEntityProvider { @@ -142,7 +138,8 @@ public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockStat @Override public List getDroppedStacks(BlockState state, LootContext.Builder builder) { - if (builder.getWorld().getGameRules().getBoolean(MinelabsGameRules.RANDOM_QUANTUM_DROPS)) { + if (builder.getWorld().getGameRules().getBoolean(MinelabsGameRules.RANDOM_QUANTUM_DROPS) + || !getTranslationKey().contains("quark")) { return super.getDroppedStacks(state, builder); } else { boolean down = getTranslationKey().contains("downquark"); diff --git a/src/main/java/be/minelabs/world/MinelabsGameRules.java b/src/main/java/be/minelabs/world/MinelabsGameRules.java index 7b3cc6b48..046d179a6 100644 --- a/src/main/java/be/minelabs/world/MinelabsGameRules.java +++ b/src/main/java/be/minelabs/world/MinelabsGameRules.java @@ -7,13 +7,13 @@ public class MinelabsGameRules { public static final GameRules.Key RANDOM_QUANTUM_DROPS = GameRuleRegistry.register( - "random_quantum_drops", GameRules.Category.DROPS, GameRuleFactory.createBooleanRule(true)); + "randomQuantumDrops", GameRules.Category.DROPS, GameRuleFactory.createBooleanRule(true)); public static final GameRules.Key BOHR_PROJECTILES = GameRuleRegistry.register( - "bohr_projectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); + "bohrProjectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); public static final GameRules.Key ALLOW_CHEMICAL_PROJECTILES = GameRuleRegistry.register( - "allow_chemical_projectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); + "allowChemicalProjectiles", GameRules.Category.SPAWNING, GameRuleFactory.createBooleanRule(true)); public static void onInitialize() { } diff --git a/src/main/resources/assets/minelabs/lang/en_us.static.json b/src/main/resources/assets/minelabs/lang/en_us.static.json index 818931881..689bfdac5 100644 --- a/src/main/resources/assets/minelabs/lang/en_us.static.json +++ b/src/main/resources/assets/minelabs/lang/en_us.static.json @@ -24,10 +24,9 @@ "text.minelabs.anti_quark.color.red": "Color: Anti-Red", "text.minelabs.anti_quark.color.green": "Color: Anti-Green", "text.minelabs.anti_quark.color.blue": "Color: Anti-Blue", - - "gamerule.random_quantum_drops": "Should Quantum blocks drop random items", - "gamerule.bohr_projectiles": "Should Bohr shoot items as projectiles", - "gamerule.allow_chemical_projectiles": "Allow chemicals to be thrown", + "gamerule.randomQuantumDrops": "Should Quantum blocks drop random items", + "gamerule.bohrProjectiles": "Should Bohr shoot items as projectiles", + "gamerule.allowChemicalProjectiles": "Allow chemicals to be thrown", "text.minelabs.no_chemical_projectiles": "A Gamerule prevents you from throwing chemicals!", "block.minelabs.charged_point": "Point Charge", "block.minelabs.fire.green_fire": "Green Fire", diff --git a/src/main/resources/assets/minelabs/lang/nl_be.static.json b/src/main/resources/assets/minelabs/lang/nl_be.static.json index bf5a94390..5fcd14790 100644 --- a/src/main/resources/assets/minelabs/lang/nl_be.static.json +++ b/src/main/resources/assets/minelabs/lang/nl_be.static.json @@ -24,10 +24,9 @@ "text.minelabs.anti_quark.color.red": "Kleur: Anti-Rood", "text.minelabs.anti_quark.color.green": "Kleur: Anti-Groen", "text.minelabs.anti_quark.color.blue": "Kleur: Anti-Blauw", - - "gamerule.random_quantum_drops": "Horen Kwantumblokken willekeurige items te laten vallen", - "gamerule.bohr_projectiles": "Kan Bohr items afschieten", - "gamerule.allow_chemical_projectiles": "Kan je met Chemicalien gooien", + "gamerule.randomQuantumDrops": "Horen Kwantumblokken willekeurige items te laten vallen", + "gamerule.bohrProjectiles": "Kan Bohr items afschieten", + "gamerule.allowChemicalProjectiles": "Kan je met Chemicalien gooien", "text.minelabs.no_chemical_projectiles": "Een Gameregel verbied het gooien van Chemicalien!", "block.minelabs.chemical.ccl4": "Tetrachloormethaan (CCl\u2084)", "block.minelabs.chemical.ch4o": "Methanol (CH\u2084O)",