Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Jul 31, 2022
1 parent a6e7dc1 commit 154f6f5
Show file tree
Hide file tree
Showing 37 changed files with 1,649 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -18,6 +19,9 @@ public interface Oxidizable extends net.minecraft.block.Oxidizable
.put(ModBlocks.COPPER_BUTTON.get(), ModBlocks.EXPOSED_COPPER_BUTTON.get())
.put(ModBlocks.EXPOSED_COPPER_BUTTON.get(), ModBlocks.WEATHERED_COPPER_BUTTON.get())
.put(ModBlocks.WEATHERED_COPPER_BUTTON.get(), ModBlocks.OXIDIZED_COPPER_BUTTON.get())
.put(Blocks.LIGHTNING_ROD, ModBlocks.EXPOSED_LIGHTNING_ROD.get())
.put(ModBlocks.EXPOSED_LIGHTNING_ROD.get(), ModBlocks.WEATHERED_LIGHTNING_ROD.get())
.put(ModBlocks.WEATHERED_LIGHTNING_ROD.get(), ModBlocks.OXIDIZED_LIGHTNING_ROD.get())
.build();
});
Supplier<BiMap<Block, Block>> OXIDATION_LEVEL_DECREASES = Suppliers.memoize(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.faboslav.friendsandfoes.block;

import net.minecraft.block.BlockState;
import net.minecraft.block.LightningRodBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;

@SuppressWarnings("deprecation")
public final class OxidizableLightningRodBlock extends LightningRodBlock implements Oxidizable
{
private final OxidationLevel OxidationLevel;

public OxidizableLightningRodBlock(
OxidationLevel OxidationLevel,
Settings settings
) {
super(settings);
this.OxidationLevel = OxidationLevel;
}

@Override
public void randomTick(
BlockState state,
ServerWorld world,
BlockPos pos,
Random random
) {
super.randomTick(state, world, pos, random);
this.tickDegradation(state, world, pos, random);
}

@Override
public boolean hasRandomTicks(BlockState state) {
return Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent();
}

public OxidationLevel getDegradationLevel() {
return this.OxidationLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ public void onStruckByLightning(
) {
super.onStruckByLightning(serverWorld, lightning);

this.setOnFire(false);
this.setHealth(this.getMaxHealth());

if (this.isDegraded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public final class ModBlocks
public static final RegistrySupplier<Block> WAXED_EXPOSED_COPPER_BUTTON;
public static final RegistrySupplier<Block> WAXED_WEATHERED_COPPER_BUTTON;
public static final RegistrySupplier<Block> WAXED_OXIDIZED_COPPER_BUTTON;
public static final RegistrySupplier<Block> EXPOSED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> WEATHERED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> OXIDIZED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> WAXED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> WAXED_EXPOSED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> WAXED_WEATHERED_LIGHTNING_ROD;
public static final RegistrySupplier<Block> WAXED_OXIDIZED_LIGHTNING_ROD;

static {
BUTTERCUP = BLOCKS.register("buttercup", () -> new FlowerBlock(StatusEffects.SATURATION, 6, AbstractBlock.Settings.of(Material.PLANT).noCollision().breakInstantly().sounds(BlockSoundGroup.GRASS)));
Expand All @@ -55,6 +62,13 @@ public final class ModBlocks
WAXED_EXPOSED_COPPER_BUTTON = BLOCKS.register("waxed_exposed_copper_button", () -> new ExposedCopperButtonBlock(AbstractBlock.Settings.copy(COPPER_BUTTON.get())));
WAXED_WEATHERED_COPPER_BUTTON = BLOCKS.register("waxed_weathered_copper_button", () -> new WeatheredCopperButtonBlock(AbstractBlock.Settings.copy(COPPER_BUTTON.get())));
WAXED_OXIDIZED_COPPER_BUTTON = BLOCKS.register("waxed_oxidized_copper_button", () -> new OxidizedCopperButtonBlock(AbstractBlock.Settings.copy(COPPER_BUTTON.get())));
EXPOSED_LIGHTNING_ROD = BLOCKS.register("exposed_lightning_rod", () -> new OxidizableLightningRodBlock(Oxidizable.OxidationLevel.EXPOSED, AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
WEATHERED_LIGHTNING_ROD = BLOCKS.register("weathered_lightning_rod", () -> new OxidizableLightningRodBlock(Oxidizable.OxidationLevel.WEATHERED, AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
OXIDIZED_LIGHTNING_ROD = BLOCKS.register("oxidized_lightning_rod", () -> new OxidizableLightningRodBlock(Oxidizable.OxidationLevel.OXIDIZED, AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
WAXED_LIGHTNING_ROD = BLOCKS.register("waxed_lightning_rod", () -> new LightningRodBlock(AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
WAXED_EXPOSED_LIGHTNING_ROD = BLOCKS.register("waxed_exposed_lightning_rod", () -> new LightningRodBlock(AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
WAXED_WEATHERED_LIGHTNING_ROD = BLOCKS.register("waxed_weathered_lightning_rod", () -> new LightningRodBlock(AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
WAXED_OXIDIZED_LIGHTNING_ROD = BLOCKS.register("waxed_oxidized_lightning_rod", () -> new LightningRodBlock(AbstractBlock.Settings.copy(Blocks.LIGHTNING_ROD)));
}

public static void initRegister() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public final class ModItems
public static final RegistrySupplier<Item> WAXED_EXPOSED_COPPER_BUTTON;
public static final RegistrySupplier<Item> WAXED_WEATHERED_COPPER_BUTTON;
public static final RegistrySupplier<Item> WAXED_OXIDIZED_COPPER_BUTTON;
public static final RegistrySupplier<Item> EXPOSED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> WEATHERED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> OXIDIZED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> WAXED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> WAXED_EXPOSED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> WAXED_WEATHERED_LIGHTNING_ROD;
public static final RegistrySupplier<Item> WAXED_OXIDIZED_LIGHTNING_ROD;

static {
COPPER_GOLEM_SPAWN_EGG = ITEMS.register("copper_golem_spawn_egg", () -> new ArchitecturySpawnEggItem(ModEntityTypes.COPPER_GOLEM, 0x9A5038, 0xE3826C, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
Expand All @@ -66,6 +73,13 @@ public final class ModItems
WAXED_EXPOSED_COPPER_BUTTON = ITEMS.register("waxed_exposed_copper_button", () -> new BlockItem(ModBlocks.WAXED_EXPOSED_COPPER_BUTTON.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_WEATHERED_COPPER_BUTTON = ITEMS.register("waxed_weathered_copper_button", () -> new BlockItem(ModBlocks.WAXED_WEATHERED_COPPER_BUTTON.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_OXIDIZED_COPPER_BUTTON = ITEMS.register("waxed_oxidized_copper_button", () -> new BlockItem(ModBlocks.WAXED_OXIDIZED_COPPER_BUTTON.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
EXPOSED_LIGHTNING_ROD = ITEMS.register("exposed_lightning_rod", () -> new BlockItem(ModBlocks.EXPOSED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WEATHERED_LIGHTNING_ROD = ITEMS.register("weathered_lightning_rod", () -> new BlockItem(ModBlocks.WEATHERED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
OXIDIZED_LIGHTNING_ROD = ITEMS.register("oxidized_lightning_rod", () -> new BlockItem(ModBlocks.OXIDIZED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_LIGHTNING_ROD = ITEMS.register("waxed_lightning_rod", () -> new BlockItem(ModBlocks.WAXED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_EXPOSED_LIGHTNING_ROD = ITEMS.register("waxed_exposed_lightning_rod", () -> new BlockItem(ModBlocks.WAXED_EXPOSED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_WEATHERED_LIGHTNING_ROD = ITEMS.register("waxed_weathered_lightning_rod", () -> new BlockItem(ModBlocks.WAXED_WEATHERED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
WAXED_OXIDIZED_LIGHTNING_ROD = ITEMS.register("waxed_oxidized_lightning_rod", () -> new BlockItem(ModBlocks.WAXED_OXIDIZED_LIGHTNING_ROD.get(), new Item.Settings().group(ItemGroup.REDSTONE).maxCount(64)));
}

public static void initRegister() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
public class ModTags
{
public static final TagKey<Block> COPPER_BUTTONS = blockTag("copper_buttons");
public static final TagKey<Block> LIGHTNING_RODS = blockTag("lightning_rods");
public static final TagKey<Block> GLARE_SPAWNABLE_ON = blockTag("glare_spawnable_on");
public static final TagKey<Block> MAULERS_SPAWNABLE_ON = blockTag("maulers_spawnable_on");

public static final TagKey<EntityType<?>> MAULER_PREY = entityTypeTag("mauler_prey");

public static final TagKey<Biome> HAS_BADLANDS_MAULER = biomeTag("has_badlands_mauler");
public static final TagKey<Biome> HAS_DESERT_MAULER = biomeTag("has_desert_mauler");
public static final TagKey<Biome> HAS_GLARE = biomeTag("has_glare");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.faboslav.friendsandfoes.mixin;

import com.faboslav.friendsandfoes.block.Oxidizable;
import com.faboslav.friendsandfoes.init.ModBlocks;
import com.google.common.base.Suppliers;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.block.Block;
import com.faboslav.friendsandfoes.util.WaxableBlocksMap;
import net.minecraft.block.BlockState;
import net.minecraft.item.AxeItem;
import net.minecraft.item.ItemUsageContext;
Expand All @@ -16,21 +12,10 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import java.util.Optional;
import java.util.function.Supplier;

@Mixin(AxeItem.class)
@SuppressWarnings({"rawtypes", "unchecked"})
public abstract class AxeItemMixin
{
private static final Supplier<BiMap<Block, Block>> WAXED_TO_UNWAXED_BLOCKS = Suppliers.memoize(() -> {
return (BiMap) ImmutableBiMap.builder()
.put(ModBlocks.WAXED_COPPER_BUTTON.get(), ModBlocks.COPPER_BUTTON.get())
.put(ModBlocks.WAXED_EXPOSED_COPPER_BUTTON.get(), ModBlocks.EXPOSED_COPPER_BUTTON.get())
.put(ModBlocks.WAXED_WEATHERED_COPPER_BUTTON.get(), ModBlocks.WEATHERED_COPPER_BUTTON.get())
.put(ModBlocks.WAXED_OXIDIZED_COPPER_BUTTON.get(), ModBlocks.OXIDIZED_COPPER_BUTTON.get())
.build();
});

@ModifyVariable(
method = "useOnBlock",
ordinal = 1,
Expand Down Expand Up @@ -72,6 +57,6 @@ private Optional<BlockState> modifyWaxedBlock(
BlockPos blockPos = context.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);

return Optional.ofNullable(WAXED_TO_UNWAXED_BLOCKS.get().get(blockState.getBlock())).map((block) -> block.getStateWithProperties(blockState));
return Optional.ofNullable(WaxableBlocksMap.WAXED_TO_UNWAXED_BLOCKS.get().get(blockState.getBlock())).map((block) -> block.getStateWithProperties(blockState));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.faboslav.friendsandfoes.mixin;

import com.faboslav.friendsandfoes.init.ModBlocks;
import com.google.common.base.Suppliers;
import com.faboslav.friendsandfoes.util.WaxableBlocksMap;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.HoneycombItem;
Expand All @@ -13,21 +11,11 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;
import java.util.function.Supplier;

@Mixin(HoneycombItem.class)
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({"rawtypes"})
public abstract class HoneycombItemMixin
{
private static final Supplier<BiMap<Block, Block>> UNWAXED_TO_WAXED_BUTTON_BLOCKS = Suppliers.memoize(() -> {
return (BiMap) ImmutableBiMap.builder()
.put(ModBlocks.COPPER_BUTTON.get(), ModBlocks.WAXED_COPPER_BUTTON.get())
.put(ModBlocks.EXPOSED_COPPER_BUTTON.get(), ModBlocks.WAXED_EXPOSED_COPPER_BUTTON.get())
.put(ModBlocks.WEATHERED_COPPER_BUTTON.get(), ModBlocks.WAXED_WEATHERED_COPPER_BUTTON.get())
.put(ModBlocks.OXIDIZED_COPPER_BUTTON.get(), ModBlocks.WAXED_OXIDIZED_COPPER_BUTTON.get())
.build();
});

@Inject(
method = "getWaxedState",
at = @At("RETURN"),
Expand All @@ -40,7 +28,7 @@ private static void getWaxedState(
var blockState = callbackInfo.getReturnValue();

if (blockState.isEmpty()) {
blockState = Optional.ofNullable((Block) ((BiMap) UNWAXED_TO_WAXED_BUTTON_BLOCKS.get()).get(state.getBlock())).map((block) -> {
blockState = Optional.ofNullable((Block) ((BiMap) WaxableBlocksMap.UNWAXED_TO_WAXED_BUTTON_BLOCKS.get()).get(state.getBlock())).map((block) -> {
return block.getStateWithProperties(state);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.faboslav.friendsandfoes.mixin;

import com.faboslav.friendsandfoes.block.Oxidizable;
import com.faboslav.friendsandfoes.init.ModTags;
import net.minecraft.block.BlockState;
import net.minecraft.block.LightningRodBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Iterator;
import java.util.Optional;

@Mixin(LightningEntity.class)
public abstract class LightningEntityMixin extends Entity
{
public LightningEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@Shadow
protected abstract BlockPos getAffectedBlockPos();

@Inject(
method = "powerLightningRod",
at = @At("HEAD")
)
public void friendsAndFoesPowerLightningRod(CallbackInfo ci) {
BlockPos blockPos = this.getAffectedBlockPos();
BlockState blockState = this.world.getBlockState(blockPos);

if (blockState.isIn(ModTags.LIGHTNING_RODS)) {
((LightningRodBlock) blockState.getBlock()).setPowered(blockState, this.world, blockPos);
}
}

@Inject(
method = "cleanOxidation",
at = @At("HEAD")
)
private static void friendsAndFoesCleanOxidation(
World world,
BlockPos pos,
CallbackInfo ci
) {
BlockState blockState = world.getBlockState(pos);
BlockPos blockPos;
BlockState blockState2;

if (blockState.isIn(ModTags.LIGHTNING_RODS)) {
blockPos = pos.offset(blockState.get(LightningRodBlock.FACING).getOpposite());
blockState2 = world.getBlockState(blockPos);
} else {
blockPos = pos;
blockState2 = blockState;
}

if (blockState2.getBlock() instanceof Oxidizable) {
world.setBlockState(blockPos, Oxidizable.getUnaffectedOxidationState(world.getBlockState(blockPos)));
BlockPos.Mutable mutable = pos.mutableCopy();
int i = world.random.nextInt(3) + 3;

for (int j = 0; j < i; ++j) {
int k = world.random.nextInt(8) + 1;
LightningEntity.cleanOxidationAround(world, blockPos, mutable, k);
}
}
}

public void customCleanOxidationAround(World world, BlockPos pos, BlockPos.Mutable mutablePos, int count) {
mutablePos.set(pos);

for(int i = 0; i < count; ++i) {
Optional<BlockPos> optional = cleanOxidationAround(world, mutablePos);
if (!optional.isPresent()) {
break;
}

mutablePos.set((Vec3i)optional.get());
}

}

private static Optional<BlockPos> cleanOxidationAround(World world, BlockPos pos) {
Iterator var2 = BlockPos.iterateRandomly(world.random, 10, pos, 1).iterator();

BlockPos blockPos;
BlockState blockState;
do {
if (!var2.hasNext()) {
return Optional.empty();
}

blockPos = (BlockPos)var2.next();
blockState = world.getBlockState(blockPos);
} while(!(blockState.getBlock() instanceof net.minecraft.block.Oxidizable));

net.minecraft.block.Oxidizable.getDecreasedOxidationState(blockState).ifPresent((state) -> {
world.setBlockState(blockPos, state);
});
world.syncWorldEvent(3002, blockPos, -1);
return Optional.of(blockPos);
}
}
Loading

0 comments on commit 154f6f5

Please sign in to comment.