Skip to content

Commit

Permalink
Week #5 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
North-West-Wind committed Dec 28, 2020
1 parent 1a44782 commit 01346ef
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 92 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.4.2-1.16.x'
version = '1.5.0-1.16.x'
group = 'com.northwestwind.moreboots' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'moreboots'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.northwestwind.moreboots.init.EffectInit;
import com.northwestwind.moreboots.init.ItemInit;
import com.northwestwind.moreboots.init.block.GlowstoneDustBlock;
import com.northwestwind.moreboots.init.block.InvisibleBlock;
import com.northwestwind.moreboots.init.block.KeybindInit;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
Expand All @@ -25,14 +26,14 @@
import net.minecraft.potion.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -41,7 +42,6 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.glfw.GLFW;

import java.util.*;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void onLivingDamage(final LivingDamageEvent event) {
if (entity.world.isRemote) return;
event.setCanceled(true);
boots.damageItem(1, entity, entity1 -> entity1.playSound(SoundEvents.BLOCK_GLASS_BREAK, 1.0f, 1.0f));
} else if (boots.getItem().equals(ItemInit.BLAZE_BOOTS)) {
} else if (boots.getItem().equals(ItemInit.BLAZE_BOOTS) || boots.getItem().equals(ItemInit.STRIDER_BOOTS)) {
DamageSource source = event.getSource();
if (source.equals(DamageSource.IN_FIRE) || source.equals(DamageSource.LAVA) || source.equals(DamageSource.ON_FIRE))
event.setCanceled(true);
Expand Down Expand Up @@ -376,16 +376,31 @@ public void onLivingUpdate(final LivingEvent.LivingUpdateEvent event) {
newBoots.setDamage(boots.getDamage());
entity.setItemStackToSlot(EquipmentSlotType.FEET, newBoots);
}
} else if (boots.getItem().equals(ItemInit.JESUS_BOOTS)) {
} else if (boots.getItem().equals(ItemInit.FLOATIE_BOOTS)) {
BlockPos pos = new BlockPos(entity.getPositionVec());
FluidState under = entity.world.getFluidState(pos.down());
if (entity.isInWater()) {
entity.setMotion(entity.getMotion().add(0, 0.1, 0));
entity.velocityChanged = true;
} else if (!entity.world.isRemote && entity.world.isAirBlock(pos.down())) {
if (!(under.getFluid().equals(Fluids.WATER) || under.getFluid().equals(Fluids.FLOWING_WATER))) return;
entity.world.setBlockState(pos.down(), BlockInit.INVISIBLE.getDefaultState());
}
} else if (!entity.world.isRemote)
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-1, -1.0D, -1), pos.add(1, -1.0D, 1))) {
FluidState under = entity.world.getFluidState(blockpos);
if (!entity.world.getBlockState(blockpos).getCollisionShape(entity.world, blockpos).equals(VoxelShapes.empty()) || !under.isTagged(FluidTags.WATER))
continue;
entity.world.setBlockState(blockpos, BlockInit.INVISIBLE.getDefaultState().with(BlockStateProperties.WATERLOGGED, true).with(InvisibleBlock.FLOWINGLOGGED, !under.isSource()));
}
} else if (boots.getItem().equals(ItemInit.STRIDER_BOOTS)) {
entity.extinguish();
BlockPos pos = new BlockPos(entity.getPositionVec());
if (entity.isInLava()) {
entity.setMotion(entity.getMotion().add(0, 0.1, 0));
entity.velocityChanged = true;
} else if (!entity.world.isRemote)
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-1, -1.0D, -1), pos.add(1, -1.0D, 1))) {
FluidState under = entity.world.getFluidState(blockpos);
if (!entity.world.getBlockState(blockpos).getCollisionShape(entity.world, blockpos).equals(VoxelShapes.empty()) || !under.isTagged(FluidTags.LAVA))
continue;
entity.world.setBlockState(blockpos, BlockInit.INVISIBLE.getDefaultState().with(InvisibleBlock.LAVALOGGED, true).with(InvisibleBlock.FLOWINGLOGGED, !under.isSource()));
}
}
}

Expand Down Expand Up @@ -423,10 +438,15 @@ public void onLivingDrop(final LivingDropsEvent event) {
int shouldDrop = rng.nextInt((1 + looting) * 2) + looting;
if (shouldDrop < 1) return;
LivingEntity entity = event.getEntityLiving();
if (!entity.getType().equals(EntityType.BAT)) return;
ItemStack stack = new ItemStack(ItemInit.BAT_HIDE, shouldDrop);
ItemEntity item = new ItemEntity(entity.world, entity.getPosX(), entity.getPosY(), entity.getPosZ(), stack);
event.getDrops().add(item);
if (entity.getType().equals(EntityType.BAT)) {
ItemStack stack = new ItemStack(ItemInit.BAT_HIDE, shouldDrop);
ItemEntity item = new ItemEntity(entity.world, entity.getPosX(), entity.getPosY(), entity.getPosZ(), stack);
event.getDrops().add(item);
} else if (entity.getType().equals(EntityType.field_233589_aE_)) {
ItemStack stack = new ItemStack(ItemInit.STRIDER_FOOT, shouldDrop);
ItemEntity item = new ItemEntity(entity.world, entity.getPosX(), entity.getPosY(), entity.getPosZ(), stack);
event.getDrops().add(item);
}
}

private void breakGlassBoots(ItemStack stack, Potion potion, LivingEntity entity) {
Expand All @@ -437,10 +457,10 @@ private void breakGlassBoots(ItemStack stack, Potion potion, LivingEntity entity
areaeffectcloudentity.setRadius(3.0F);
areaeffectcloudentity.setRadiusOnUse(-0.5F);
areaeffectcloudentity.setWaitTime(10);
areaeffectcloudentity.setRadiusPerTick(-areaeffectcloudentity.getRadius() / (float)areaeffectcloudentity.getDuration());
areaeffectcloudentity.setRadiusPerTick(-areaeffectcloudentity.getRadius() / (float) areaeffectcloudentity.getDuration());
areaeffectcloudentity.setPotion(potion);

for(EffectInstance effectinstance : PotionUtils.getFullEffectsFromItem(stack)) {
for (EffectInstance effectinstance : PotionUtils.getFullEffectsFromItem(stack)) {
areaeffectcloudentity.addEffect(new EffectInstance(effectinstance));
}

Expand Down
50 changes: 21 additions & 29 deletions src/main/java/com/northwestwind/moreboots/handler/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.northwestwind.moreboots.handler;

import com.northwestwind.moreboots.init.BlockInit;
import com.northwestwind.moreboots.init.block.InvisibleBlock;
import it.unimi.dsi.fastutil.objects.Object2ByteLinkedOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -9,10 +12,16 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

Expand Down Expand Up @@ -64,71 +73,54 @@ public static void changeGroundBlocks(LivingEntity living, World worldIn, BlockP
if (blockstate1.isAir(worldIn, blockpos$mutable)) {
BlockState blockstate2 = worldIn.getBlockState(blockpos);
boolean shouldChange = target.contains(blockstate2.getBlock());
if (shouldChange) worldIn.setBlockState(blockpos, to.get(new Random().nextInt(to.size())).getDefaultState());
if (shouldChange)
worldIn.setBlockState(blockpos, to.get(new Random().nextInt(to.size())).getDefaultState());
}
}
}
}

public static byte[] objToBytes(Object obj)
{
public static byte[] objToBytes(Object obj) {
byte[] bytes = null;
ByteArrayOutputStream bos = null;
ObjectOutputStream oos = null;
try
{
try {
bos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
bytes = bos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally
{
} finally {
try {
if(oos != null)oos.close();
if(bos != null)bos.close();
} catch(IOException ex) {
if (oos != null) oos.close();
if (bos != null) bos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return bytes;
}

public static Object bytesToObj(byte[] bytes)
{
public static Object bytesToObj(byte[] bytes) {
Object obj = null;
ByteArrayInputStream bis = null;
ObjectInputStream ois = null;
try
{
try {
bis = new ByteArrayInputStream(bytes);
ois = new ObjectInputStream(bis);
obj = ois.readObject();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
} finally
{
} finally {
try {
if (ois != null) ois.close();
if (bis != null) bis.close();
} catch(IOException ex) {
} catch (IOException ex) {
ex.printStackTrace();
}
}
return obj;
}

@Nullable
public static Entity findEntityByUUID(UUID uuid, ServerWorld world) {
Stream<Entity> entities = world.getEntities();
LivingEntity entity = null;
for(Entity ent : entities.toArray(Entity[]::new)) {
if(ent.getUniqueID().equals(uuid)) {
entity = (LivingEntity) ent;
}
}
return entity;
}
}
18 changes: 13 additions & 5 deletions src/main/java/com/northwestwind/moreboots/init/ItemInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.northwestwind.moreboots.Reference;
import com.northwestwind.moreboots.init.item.ArmorItemBase;
import com.northwestwind.moreboots.init.item.ItemBase;
import com.northwestwind.moreboots.init.item.SniperCrossbowItem;
import net.minecraft.block.Blocks;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
Expand Down Expand Up @@ -59,12 +58,14 @@ public class ItemInit {
public static final Item KA_BOOTS = registerBoots(ModArmorMaterial.KA, "ka_boots");
public static final Item GLASS_BOOTS = registerBoots(ModArmorMaterial.GLASS, "glass_boots");
public static final Item GLASS_BOOTS_EMPTY = registerBoots(ModArmorMaterial.GLASS_EMPTY, "glass_boots_empty");
public static final Item JESUS_BOOTS = registerBoots(ModArmorMaterial.JESUS, "jesus_boots");
public static final Item FLOATIE_BOOTS = registerBoots(ModArmorMaterial.FLOATIE, "floatie_boots", true);
public static final Item STRIDER_BOOTS = registerBoots(ModArmorMaterial.STRIDER, "strider_boots", true);
//public static final Item SNIPER_BOOTS = registerBoots(ModArmorMaterial.SNIPER, "sniper_boots");

public static final Item QUARTZ_INGOT = new ItemBase(new Item.Properties().group(MoreBoots.MoreBootsItemGroup.INSTANCE), "quartz_ingot").setRegistryName("quartz_ingot");
public static final Item METAL_MIX = new ItemBase(new Item.Properties().group(MoreBoots.MoreBootsItemGroup.INSTANCE), "metal_mix").setRegistryName("metal_mix");
public static final Item BAT_HIDE = new ItemBase(new Item.Properties().group(MoreBoots.MoreBootsItemGroup.INSTANCE), "bat_hide").setRegistryName("bat_hide");
public static final Item STRIDER_FOOT = new ItemBase(new Item.Properties().group(MoreBoots.MoreBootsItemGroup.INSTANCE), "strider_foot").setRegistryName("strider_foot");

//public static final Item CROSSBOW = new SniperCrossbowItem().setRegistryName("minecraft", "crossbow");

Expand Down Expand Up @@ -102,18 +103,24 @@ public static void registerItems(final RegistryEvent.Register<Item> event) {
event.getRegistry().register(KA_BOOTS);
event.getRegistry().register(GLASS_BOOTS);
event.getRegistry().register(GLASS_BOOTS_EMPTY);
event.getRegistry().register(JESUS_BOOTS);
event.getRegistry().register(FLOATIE_BOOTS);
event.getRegistry().register(STRIDER_BOOTS);
//event.getRegistry().register(SNIPER_BOOTS);

event.getRegistry().register(QUARTZ_INGOT);
event.getRegistry().register(METAL_MIX);
event.getRegistry().register(BAT_HIDE);
event.getRegistry().register(STRIDER_FOOT);

//event.getRegistry().register(CROSSBOW);
}

public static Item registerBoots(IArmorMaterial material, String registryName) {
return new ArmorItemBase(material, registryName).setRegistryName(registryName);
return registerBoots(material, registryName, false);
}

public static Item registerBoots(IArmorMaterial material, String registryName, boolean isNetherite) {
return new ArmorItemBase(material, registryName, isNetherite).setRegistryName(registryName);
}

public enum ModArmorMaterial implements IArmorMaterial {
Expand Down Expand Up @@ -180,7 +187,8 @@ public enum ModArmorMaterial implements IArmorMaterial {
GLASS_EMPTY(Reference.MODID + ":glass", 10, new int[] { 4, 1, 1, 1 }, 20, SoundEvents.ITEM_BOTTLE_FILL, 0.0f, 0.0f, () -> Ingredient.fromItems(Items.GLASS)),
GLASS(Reference.MODID + ":glass", 10, new int[] { 4, 1, 1, 1 }, 20, SoundEvents.BLOCK_GLASS_BREAK, 0.0f, 0.0f, () -> Ingredient.fromItems(Items.GLASS)),
SNIPER(Reference.MODID + ":sniper", 8, new int[] { 2, 1, 1, 1 }, 12, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0.0f, 0.0f, 90000, () -> Ingredient.fromItems(Items.TIPPED_ARROW)),
JESUS(Reference.MODID + ":jesus", 40, new int[] { 4, 1, 1, 1 }, 15, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 1.0f, 0.0f, 160000, () -> Ingredient.fromItems(Items.field_234759_km_));
FLOATIE(Reference.MODID + ":floatie", 40, new int[] { 4, 1, 1, 1 }, 15, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 1.0f, 0.0f, 160000, () -> Ingredient.fromItems(Items.field_234759_km_)),
STRIDER(Reference.MODID + ":strider", 40, new int[] { 4, 1, 1, 1 }, 15, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 1.0f, 0.0f, 160000, () -> Ingredient.fromItems(ItemInit.STRIDER_FOOT));
private static final int[] MAX_DAMAGE_ARRAY = new int[] { 16, 16, 16, 16 };
private final String name;
private final float maxDamageFactor;
Expand Down
Loading

0 comments on commit 01346ef

Please sign in to comment.