001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.server.entity.living;
019
020import net.tridentsdk.base.Position;
021import net.tridentsdk.entity.Entity;
022import net.tridentsdk.entity.living.Creeper;
023import net.tridentsdk.entity.living.Player;
024import net.tridentsdk.entity.types.EntityType;
025import net.tridentsdk.event.entity.EntityDamageEvent;
026import net.tridentsdk.meta.nbt.ByteTag;
027import net.tridentsdk.meta.nbt.CompoundTag;
028import net.tridentsdk.meta.nbt.FloatTag;
029import net.tridentsdk.meta.nbt.ShortTag;
030import net.tridentsdk.server.data.MetadataType;
031import net.tridentsdk.server.data.ProtocolMetadata;
032import net.tridentsdk.server.entity.TridentLivingEntity;
033
034import java.util.UUID;
035
036public class TridentCreeper extends TridentLivingEntity implements Creeper {
037    private volatile boolean charged;
038    private volatile float explosionRadius;
039    private volatile short fuse;
040    private volatile boolean ignited;
041
042    public TridentCreeper(UUID id, Position spawnLocation) {
043        super(id, spawnLocation);
044    }
045
046    @Override
047    public void doLoad(CompoundTag tag) {
048        if (tag.containsTag("powered")) {
049            this.charged = ((ByteTag) tag.getTag("powered")).value() == 1;
050        }
051
052        this.explosionRadius = ((FloatTag) tag.getTag("ExplosionRadius")).value();
053        this.fuse = ((ShortTag) tag.getTag("Fuse")).value();
054        this.ignited = ((ByteTag) tag.getTag("ignited")).value() == 1;
055    }
056
057    @Override
058    protected void doEncodeMeta(ProtocolMetadata protocolMeta) {
059        protocolMeta.setMeta(16, MetadataType.BYTE, ignited ? 1 : -1);
060        protocolMeta.setMeta(17, MetadataType.BYTE, charged ? 1 : 0);
061    }
062
063    @Override
064    public boolean isElectric() {
065        return charged;
066    }
067
068    @Override
069    public void setElectric(boolean powered) {
070        this.charged = powered;
071    }
072
073    @Override
074    public float explosionRadius() {
075        return explosionRadius;
076    }
077
078    @Override
079    public void setExplosionRadius(float rad) {
080        this.explosionRadius = rad;
081    }
082
083    @Override
084    public void hide(Entity entity) {
085
086    }
087
088    @Override
089    public void show(Entity entity) {
090
091    }
092
093    @Override
094    public EntityDamageEvent lastDamageEvent() {
095        return null;
096    }
097
098    @Override
099    public Player lastPlayerDamager() {
100        return null;
101    }
102
103    @Override
104    public EntityType type() {
105        return EntityType.CREEPER;
106    }
107}