Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamerules rule (3 new)! #815

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/generated/assets/minelabs/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/main/generated/assets/minelabs/lang/nl_be.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/main/generated/assets/minelabs/lang/nl_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
}
2 changes: 2 additions & 0 deletions src/main/java/be/minelabs/Minelabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void onInitialize() {
CraftingRecipes.onInitialize();
Villagers.onInitialize();

MinelabsGameRules.onInitialize();
ServerModEvents.onInitialize();
Criteria.onInitialize();
}
Expand Down
42 changes: 35 additions & 7 deletions src/main/java/be/minelabs/block/blocks/QuantumfieldBlock.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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;
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;
import net.minecraft.block.BlockState;
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;
Expand All @@ -23,6 +29,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;
Expand All @@ -33,6 +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, 2);


public QuantumfieldBlock() {
Expand All @@ -45,15 +55,15 @@ 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));

}

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);
}

Expand Down Expand Up @@ -85,15 +95,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<Block, BlockState> 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) {
Expand All @@ -104,7 +114,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);
}

Expand All @@ -121,7 +131,25 @@ 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 % 3 == 0) {
drop = 0;
}
world.setBlockState(pos, state.with(DROP_KIND, drop), Block.NOTIFY_ALL);
}
}

@Override
public List<ItemStack> 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");
int kind = state.get(DROP_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)));
}
}
}
45 changes: 30 additions & 15 deletions src/main/java/be/minelabs/entity/BohrBlueprintEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -32,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;
Expand Down Expand Up @@ -132,9 +134,9 @@ 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))
tryLaunchParticle(Items.ELECTRON);
electronEjectProgress = 1f;
}
}
Expand Down Expand Up @@ -170,7 +172,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))
Expand Down Expand Up @@ -330,11 +332,24 @@ 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);
/**
* 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)) {
launchParticle(item);
} else {
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();
}

Expand Down Expand Up @@ -430,11 +445,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<Entity> 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();
}
}
Expand All @@ -461,7 +476,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++) {
Expand Down Expand Up @@ -529,19 +544,19 @@ 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);
}

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);
}

Expand Down
Loading